#include <Object_Manager_Base.h>
Inheritance diagram for ACE_OS_Object_Manager:


Public Types | |
| enum | Preallocated_Object { ACE_OS_EMPTY_PREALLOCATED_OBJECT, ACE_OS_PREALLOCATED_OBJECTS } |
| Unique identifiers for preallocated objects. More... | |
Public Member Functions | |
| virtual int | init (void) |
| Explicitly initialize. | |
| virtual int | fini (void) |
| Explicitly destroy. | |
| ACE_OS_Object_Manager (void) | |
| Constructor. | |
| ~ACE_OS_Object_Manager (void) | |
| Destructor. | |
| int | at_exit (ACE_EXIT_HOOK func) |
| For <ACE_OS::atexit> support. | |
Static Public Member Functions | |
| int | starting_up (void) |
| int | shutting_down (void) |
| sigset_t * | default_mask (void) |
| ACE_Thread_Hook * | thread_hook (void) |
| Returns the current thread hook for the process. | |
| ACE_Thread_Hook * | thread_hook (ACE_Thread_Hook *new_thread_hook) |
| Returns the existing thread hook and assign a . | |
| ACE_OS_Object_Manager * | instance (void) |
| Accessor to singleton instance. | |
| void | print_error_message (unsigned int line_number, const ACE_TCHAR *message) |
| For use by init () and fini (), to consolidate error reporting. | |
Public Attributes | |
| sigset_t * | default_mask_ |
| Default signal set used, for example, in ACE_Sig_Guard. | |
| ACE_Thread_Hook * | thread_hook_ |
| Thread hook that's used by this process. | |
| ACE_OS_Exit_Info | exit_info_ |
| For at_exit support. | |
Static Public Attributes | |
| ACE_OS_Object_Manager * | instance_ = 0 |
| Singleton instance pointer. | |
| void * | preallocated_object [ACE_OS_PREALLOCATED_OBJECTS] = { 0 } |
| Table of preallocated objects. | |
Friends | |
| class | ACE_Object_Manager |
| This class is for internal use by ACE_OS, etc., only. | |
| class | ACE_OS_Object_Manager_Manager |
| class | ACE_TSS_Cleanup |
| class | ACE_TSS_Emulation |
| class | ACE_Log_Msg |
| void | ACE_OS_Object_Manager_Internal_Exit_Hook () |
|
|
Unique identifiers for preallocated objects.
Definition at line 150 of file Object_Manager_Base.h.
00151 {
00152 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00153 ACE_OS_MONITOR_LOCK,
00154 ACE_TSS_CLEANUP_LOCK,
00155 ACE_LOG_MSG_INSTANCE_LOCK,
00156 # if defined (ACE_HAS_TSS_EMULATION)
00157 ACE_TSS_KEY_LOCK,
00158 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00159 ACE_TSS_BASE_LOCK,
00160 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
00161 # endif /* ACE_HAS_TSS_EMULATION */
00162 # else
00163 // Without ACE_MT_SAFE, There are no preallocated objects. Make
00164 // sure that the preallocated_array size is at least one by
00165 // declaring this dummy . . .
00166 ACE_OS_EMPTY_PREALLOCATED_OBJECT,
00167 # endif /* ACE_MT_SAFE */
00168
00169 /// This enum value must be last!
00170 ACE_OS_PREALLOCATED_OBJECTS
00171 };
|
|
|
Constructor.
Definition at line 85 of file Object_Manager_Base.cpp. References ACE_SEH_Default_Exception_Handler(), ACE_SEH_Default_Exception_Selector(), init(), and instance_.
00087 : thread_hook_ (0) 00088 , exit_info_ () 00089 #if defined (ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS) 00090 , seh_except_selector_ (ACE_SEH_Default_Exception_Selector) 00091 , seh_except_handler_ (ACE_SEH_Default_Exception_Handler) 00092 #endif /* ACE_HAS_WIN32_STRUCTURAL_EXCEPTIONS */ 00093 { 00094 // If instance_ was not 0, then another ACE_OS_Object_Manager has 00095 // already been instantiated (it is likely to be one initialized by 00096 // way of library/DLL loading). Let this one go through 00097 // construction in case there really is a good reason for it (like, 00098 // ACE is a static/archive library, and this one is the non-static 00099 // instance (with ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has 00100 // a good reason for creating a separate one) but the original one 00101 // will be the one retrieved from calls to 00102 // ACE_Object_Manager::instance(). 00103 00104 // Be sure that no further instances are created via instance (). 00105 if (instance_ == 0) 00106 instance_ = this; 00107 00108 init (); 00109 } |
|
|
Destructor.
Definition at line 111 of file Object_Manager_Base.cpp. References fini().
00112 {
00113 dynamically_allocated_ = 0; // Don't delete this again in fini()
00114 fini ();
00115 }
|
|
|
For <ACE_OS::atexit> support.
Definition at line 397 of file Object_Manager_Base.cpp. References ace_exit_hook_marker, and ACE_OS_Exit_Info::at_exit_i(). Referenced by ACE_OS::atexit().
00398 {
00399 return exit_info_.at_exit_i (&ace_exit_hook_marker,
00400 reinterpret_cast <ACE_CLEANUP_FUNC> (func),
00401 0);
00402 }
|
|
|
Accesses a default signal set used, for example, in methods. Definition at line 118 of file Object_Manager_Base.cpp. References default_mask_, and instance(). Referenced by ACE_Object_Manager::default_mask().
00119 {
00120 return ACE_OS_Object_Manager::instance ()->default_mask_;
00121 }
|
|
|
Explicitly destroy.
Implements ACE_Object_Manager_Base. Definition at line 285 of file Object_Manager_Base.cpp. References ACE_LIB_TEXT, ACE_OS_DELETE_PREALLOCATED_OBJECT, ACE_OS_Exit_Info::call_hooks(), default_mask_, ACE_Object_Manager_Base::fini(), instance_, preallocated_object, print_error_message(), ACE_Object_Manager_Base::shutting_down_i(), and ACE_OS::socket_fini(). Referenced by ACE_OS_Object_Manager_Internal_Exit_Hook(), ACE_Object_Manager::fini(), and ~ACE_OS_Object_Manager().
00286 {
00287 if (instance_ == 0 || shutting_down_i ())
00288 // Too late. Or, maybe too early. Either fini () has already
00289 // been called, or init () was never called.
00290 return object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1;
00291
00292 // No mutex here. Only the main thread should destroy the singleton
00293 // ACE_OS_Object_Manager instance.
00294
00295 // Indicate that the ACE_OS_Object_Manager instance is being shut
00296 // down. This object manager should be the last one to be shut
00297 // down.
00298 object_manager_state_ = OBJ_MAN_SHUTTING_DOWN;
00299
00300 // If another Object_Manager has registered for termination, do it.
00301 if (next_)
00302 {
00303 next_->fini ();
00304 next_ = 0; // Protect against recursive calls.
00305 }
00306
00307 // Call all registered cleanup hooks, in reverse order of
00308 // registration.
00309 exit_info_.call_hooks ();
00310
00311 // Only clean up preallocated objects when the singleton Instance is being
00312 // destroyed.
00313 if (this == instance_)
00314 {
00315 // Close down Winsock (no-op on other platforms).
00316 ACE_OS::socket_fini ();
00317
00318 #if ! defined (ACE_HAS_STATIC_PREALLOCATION)
00319 // Cleanup the dynamically preallocated objects.
00320 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00321 # if !defined(ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK)
00322 if (ACE_OS::thread_mutex_destroy
00323 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00324 (reinterpret_cast <ACE_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_OS_MONITOR_LOCK])) != 0)
00325 ACE_OS_Object_Manager::print_error_message (
00326 __LINE__, ACE_LIB_TEXT ("ACE_OS_MONITOR_LOCK"));
00327 # endif /* ! ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK */
00328 ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_thread_mutex_t,
00329 ACE_OS_MONITOR_LOCK)
00330 # if !defined(ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK)
00331 if (ACE_OS::recursive_mutex_destroy
00332 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00333 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_CLEANUP_LOCK])) != 0)
00334 ACE_OS_Object_Manager::print_error_message (
00335 __LINE__, ACE_LIB_TEXT ("ACE_TSS_CLEANUP_LOCK"));
00336 # endif /* ! ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK */
00337 ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t,
00338 ACE_TSS_CLEANUP_LOCK)
00339 # if !defined(ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK)
00340 if (ACE_OS::thread_mutex_destroy
00341 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00342 (reinterpret_cast <ACE_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object [ACE_LOG_MSG_INSTANCE_LOCK])) != 0)
00343 ACE_OS_Object_Manager::print_error_message (
00344 __LINE__, ACE_LIB_TEXT ("ACE_LOG_MSG_INSTANCE_LOCK "));
00345 # endif /* ! ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK */
00346 ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_thread_mutex_t,
00347 ACE_LOG_MSG_INSTANCE_LOCK)
00348 # if defined (ACE_HAS_TSS_EMULATION)
00349 # if !defined(ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK)
00350 if (ACE_OS::recursive_mutex_destroy
00351 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00352 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_KEY_LOCK])) != 0)
00353 ACE_OS_Object_Manager::print_error_message (
00354 __LINE__, ACE_LIB_TEXT ("ACE_TSS_KEY_LOCK"));
00355 # endif /* ! ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK */
00356 ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t,
00357 ACE_TSS_KEY_LOCK)
00358 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00359 # if !defined(ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK)
00360 if (ACE_OS::recursive_mutex_destroy
00361 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00362 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0)
00363 ACE_OS_Object_Manager::print_error_message (
00364 __LINE__, ACE_LIB_TEXT ("ACE_TSS_BASE_LOCK"));
00365 # endif /* ! ACE_HAS_BROKEN_PREALLOCATED_OBJECTS_AFTER_FORK */
00366 ACE_OS_DELETE_PREALLOCATED_OBJECT (ACE_recursive_thread_mutex_t,
00367 ACE_TSS_BASE_LOCK)
00368 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
00369 # endif /* ACE_HAS_TSS_EMULATION */
00370 # if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
00371 ACE_CE_Errno::fini ();
00372 # endif /* ACE_HAS_WINCE_BROKEN_ERRNO */
00373 # endif /* ACE_MT_SAFE */
00374 #endif /* ! ACE_HAS_STATIC_PREALLOCATION */
00375 }
00376
00377 delete default_mask_;
00378 default_mask_ = 0;
00379
00380 // Indicate that this ACE_OS_Object_Manager instance has been shut down.
00381 object_manager_state_ = OBJ_MAN_SHUT_DOWN;
00382
00383 if (dynamically_allocated_)
00384 {
00385 delete this;
00386 }
00387
00388 if (this == instance_)
00389 instance_ = 0;
00390
00391 return 0;
00392 }
|
|
|
Explicitly initialize.
Implements ACE_Object_Manager_Base. Definition at line 200 of file Object_Manager_Base.cpp. References ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_OS_Object_Manager_Internal_Exit_Hook(), ACE_OS_PREALLOCATE_OBJECT, default_mask_, instance_, preallocated_object, print_error_message(), ACE_OS::set_exit_hook(), ACE_OS::sigfillset(), ACE_OS::socket_init(), and ACE_Object_Manager_Base::starting_up_i(). Referenced by ACE_OS_Object_Manager().
00201 {
00202 if (starting_up_i ())
00203 {
00204 // First, indicate that this ACE_OS_Object_Manager instance is being
00205 // initialized.
00206 object_manager_state_ = OBJ_MAN_INITIALIZING;
00207
00208 if (this == instance_)
00209 {
00210 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00211 # if defined (ACE_HAS_WINCE_BROKEN_ERRNO)
00212 ACE_CE_Errno::init ();
00213 # endif /* ACE_HAS_WINCE_BROKEN_ERRNO */
00214 ACE_OS_PREALLOCATE_OBJECT (ACE_thread_mutex_t, ACE_OS_MONITOR_LOCK)
00215 if (ACE_OS::thread_mutex_init
00216 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00217 (reinterpret_cast <ACE_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_OS_MONITOR_LOCK])) != 0)
00218 ACE_OS_Object_Manager::print_error_message (
00219 __LINE__, ACE_LIB_TEXT ("ACE_OS_MONITOR_LOCK"));
00220 ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t,
00221 ACE_TSS_CLEANUP_LOCK)
00222 if (ACE_OS::recursive_mutex_init
00223 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00224 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_CLEANUP_LOCK])) != 0)
00225 ACE_OS_Object_Manager::print_error_message (
00226 __LINE__, ACE_LIB_TEXT ("ACE_TSS_CLEANUP_LOCK"));
00227 ACE_OS_PREALLOCATE_OBJECT (ACE_thread_mutex_t,
00228 ACE_LOG_MSG_INSTANCE_LOCK)
00229 if (ACE_OS::thread_mutex_init
00230 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00231 (reinterpret_cast <ACE_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_LOG_MSG_INSTANCE_LOCK])) != 0)
00232 ACE_OS_Object_Manager::print_error_message (
00233 __LINE__, ACE_LIB_TEXT ("ACE_LOG_MSG_INSTANCE_LOCK"));
00234 # if defined (ACE_HAS_TSS_EMULATION)
00235 ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t,
00236 ACE_TSS_KEY_LOCK)
00237 if (ACE_OS::recursive_mutex_init
00238 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00239 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_KEY_LOCK])) != 0)
00240 ACE_OS_Object_Manager::print_error_message (
00241 __LINE__, ACE_LIB_TEXT ("ACE_TSS_KEY_LOCK"));
00242 # if defined (ACE_HAS_THREAD_SPECIFIC_STORAGE)
00243 ACE_OS_PREALLOCATE_OBJECT (ACE_recursive_thread_mutex_t,
00244 ACE_TSS_BASE_LOCK)
00245 if (ACE_OS::recursive_mutex_init
00246 // This line must not be broken to avoid tickling a bug with SunC++'s preprocessor.
00247 (reinterpret_cast <ACE_recursive_thread_mutex_t *> (ACE_OS_Object_Manager::preallocated_object[ACE_TSS_BASE_LOCK])) != 0)
00248 ACE_OS_Object_Manager::print_error_message (
00249 __LINE__, ACE_LIB_TEXT ("ACE_TSS_BASE_LOCK"));
00250 # endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE */
00251 # endif /* ACE_HAS_TSS_EMULATION */
00252 # endif /* ACE_MT_SAFE */
00253
00254 // Open Winsock (no-op on other platforms).
00255 ACE_OS::socket_init (ACE_WSOCK_VERSION);
00256
00257 // Register the exit hook, for use by ACE_OS::exit ().
00258 ACE_OS::set_exit_hook (&ACE_OS_Object_Manager_Internal_Exit_Hook);
00259 }
00260
00261 ACE_NEW_RETURN (default_mask_, sigset_t, -1);
00262 ACE_OS::sigfillset (default_mask_);
00263
00264 // Finally, indicate that the ACE_OS_Object_Manager instance has
00265 // been initialized.
00266 object_manager_state_ = OBJ_MAN_INITIALIZED;
00267
00268 # if defined (ACE_WIN32)
00269 ACE_OS::win32_versioninfo_.dwOSVersionInfoSize =
00270 sizeof (OSVERSIONINFO);
00271 ::GetVersionEx (&ACE_OS::win32_versioninfo_);
00272 # endif /* ACE_WIN32 */
00273 return 0;
00274 } else {
00275 // Had already initialized.
00276 return 1;
00277 }
00278 }
|
|
|
Accessor to singleton instance.
Definition at line 175 of file Object_Manager_Base.cpp. References ACE_NEW_RETURN, ACE_Object_Manager_Base::dynamically_allocated_, and instance_. Referenced by ACE_OS_Object_Manager_Internal_Exit_Hook(), ACE_OS_Object_Manager_Manager::ACE_OS_Object_Manager_Manager(), ACE_OS::atexit(), default_mask(), ACE_Object_Manager::init(), and thread_hook().
00176 {
00177 // This function should be called during construction of static
00178 // instances, or before any other threads have been created in the
00179 // process. So, it's not thread safe.
00180
00181 if (instance_ == 0)
00182 {
00183 ACE_OS_Object_Manager *instance_pointer;
00184
00185 ACE_NEW_RETURN (instance_pointer,
00186 ACE_OS_Object_Manager,
00187 0);
00188 // I (coryan) removed it, using asserts in the OS layer
00189 // brings down the Log msg stuff
00190 // ACE_ASSERT (instance_pointer == instance_);
00191
00192 instance_pointer->dynamically_allocated_ = 1;
00193
00194 }
00195
00196 return instance_;
00197 }
|
|
||||||||||||
|
For use by init () and fini (), to consolidate error reporting.
Definition at line 405 of file Object_Manager_Base.cpp. References ACE_LIB_TEXT, ACE_TCHAR, and ACE_TEXT_ALWAYS_CHAR. Referenced by fini(), and init().
00407 {
00408 // To avoid duplication of these const strings in OS.o.
00409 #if !defined (ACE_HAS_WINCE)
00410 fprintf (stderr, "ace/OS.cpp, line %u: %s ",
00411 line_number,
00412 ACE_TEXT_ALWAYS_CHAR (message));
00413 perror ("failed");
00414 #else
00415 // @@ Need to use the following information.
00416 ACE_UNUSED_ARG (line_number);
00417 ACE_UNUSED_ARG (message);
00418
00419 ACE_TCHAR *lpMsgBuf = 0;
00420 ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
00421 FORMAT_MESSAGE_FROM_SYSTEM,
00422 0,
00423 ::GetLastError (),
00424 MAKELANGID (LANG_NEUTRAL,
00425 SUBLANG_DEFAULT),
00426 // Default language
00427 (ACE_TCHAR *) &lpMsgBuf,
00428 0,
00429 0);
00430 ::MessageBox (NULL,
00431 lpMsgBuf,
00432 ACE_LIB_TEXT ("ACE_OS error"),
00433 MB_OK);
00434 #endif
00435 }
|
|
|
Returns 1 after the has been destroyed. See <ACE_Object_Manager::shutting_down> for more information. Definition at line 446 of file Object_Manager_Base.cpp. References instance_, and ACE_Object_Manager_Base::shutting_down_i().
00447 {
00448 return ACE_OS_Object_Manager::instance_
00449 ? instance_->shutting_down_i ()
00450 : 1;
00451 }
|
|
|
Returns 1 before the has been constructed. See <ACE_Object_Manager::starting_up> for more information. Definition at line 438 of file Object_Manager_Base.cpp. References instance_, and ACE_Object_Manager_Base::starting_up_i(). Referenced by ACE_Trace::ACE_Trace(), ACE_Log_Msg::instance(), and ACE_Trace::~ACE_Trace().
00439 {
00440 return ACE_OS_Object_Manager::instance_
00441 ? instance_->starting_up_i ()
00442 : 1;
00443 }
|
|
|
Returns the existing thread hook and assign a .
Definition at line 166 of file Object_Manager_Base.cpp. References instance(), and thread_hook_.
00167 {
00168 ACE_OS_Object_Manager *os_om = ACE_OS_Object_Manager::instance ();
00169 ACE_Thread_Hook *old_hook = os_om->thread_hook_;
00170 os_om->thread_hook_ = new_thread_hook;
00171 return old_hook;
00172 }
|
|
|
Returns the current thread hook for the process.
Definition at line 124 of file Object_Manager_Base.cpp. References instance(), and thread_hook_. Referenced by ACE_OS_Thread_Adapter::invoke(), ACE_Thread_Adapter::invoke_i(), and ACE_Thread_Hook::thread_hook().
00125 {
00126 return ACE_OS_Object_Manager::instance ()->thread_hook_;
00127 }
|
|
|
Definition at line 241 of file Object_Manager_Base.h. |
|
|
This class is for internal use by ACE_OS, etc., only.
Definition at line 237 of file Object_Manager_Base.h. |
|
|
Definition at line 74 of file Object_Manager_Base.cpp.
00075 {
00076 if (ACE_OS_Object_Manager::instance_)
00077 ACE_OS_Object_Manager::instance ()->fini ();
00078 }
|
|
|
Definition at line 238 of file Object_Manager_Base.h. |
|
|
Definition at line 239 of file Object_Manager_Base.h. |
|
|
Definition at line 240 of file Object_Manager_Base.h. |
|
|
Default signal set used, for example, in ACE_Sig_Guard.
Definition at line 218 of file Object_Manager_Base.h. Referenced by default_mask(), fini(), and init(). |
|
|
For at_exit support.
Definition at line 224 of file Object_Manager_Base.h. |
|
|
Singleton instance pointer.
Definition at line 80 of file Object_Manager_Base.cpp. Referenced by ACE_OS_Object_Manager(), fini(), ACE_Object_Manager::fini(), init(), instance(), shutting_down(), and starting_up(). |
|
|
Table of preallocated objects.
Definition at line 83 of file Object_Manager_Base.cpp. |
|
|
Thread hook that's used by this process.
Definition at line 221 of file Object_Manager_Base.h. Referenced by thread_hook(). |
1.3.6