Manager for ACE library services and singleton cleanup. More...
#include <Object_Manager.h>


Manager for ACE library services and singleton cleanup.
The ACE_Object_Manager manages cleanup of objects, typically singletons, at program termination. In addition to managing the cleanup of the ACE library, it provides an interface for application to register objects to be cleaned up. This class also shuts down ACE library services, so that they can reclaim their storage, at program termination. It works by creating a static instance whose destructor gets called along with those of all other static objects. Hooks are provided for application code to register objects and arrays for cleanup, e.g., destruction. The order of such cleanup calls is in the reverse order of registration, i.e., that last object/array to register gets cleaned up first. The ACE_Object_Manager API includes ACE_Managed_Object. That class is contained in a separate file because it is a template class, and some compilers require that template and non-template class definitions appear in separate files. Please see ace/Managed_Object.h for a description of that part of the API. In summary, ACE_Managed_Object provides two adapters, the ACE_Cleanup_Adapter and ACE_Managed_Object template classes for adapting objects of any type to be easily managed by the ACE_Object_Manager. There are several mechanisms for adapting objects and arrays for cleanup at program termination, in roughly increasing order of ease-of-use: 1) Derive the object's class from ACE_Cleanup. 2) Allow the ACE_Object_Manager to both dynamically allocate and deallocate the object. 3) Provide an <ACE_CLEANUP_FUNC> cleanup hook for the object or array. 4) Allow the ACE_Object_Manager to both preallocate the object or array, either statically in global data or dynamically on the heap, when its singleton instance is construction.
There are also several mechanisms for registering objects and arrays for cleanup. In decreasing order of flexibility and complexity (with the exception of the last mechanism):
1) ACE_Object_Manager::at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param); can be used to register any object or array for any cleanup activity at program termination. 2) ACE_Object_Manager::at_exit (ACE_Cleanup *object, void *param = 0); can be used to register an ACE_Cleanup object for any cleanup activity at program termination. The final mechanism is not general purpose, but can only be used to allocate objects and arrays at program startup: 3) ACE_Managed_Object::get_preallocated_object (ACE_Object_Manager::Preallocated_Object id); and ACE_Managed_Object::get_preallocated_array (ACE_Object_Manager::Preallocated_Array id); can only be used to allocate objects at program startup, either in global data or on the heap (selected at compile time). These are intended to replace static locks, etc. Instead of creating a static ACE_Object_Manager instance, one can alternatively be created on the stack of the main program thread. It is created just after entry to main (int, char *[]), and before any existing code in that function is executed. To enable this alternative, add define ACE_HAS_NONSTATIC_OBJECT_MANAGER before including the platform specific config-* file in ace/config.h prior to building the ACE library and your applications. This define is enabled in some config files that are supplied with ACE.
To ensure a static object manager is used, undef ACE_HAS_NONSTATIC_OBJECT_MANAGER *after* including the platform specific config-* file. Note that the ACE_Object_Manager _must_ be created before any threads are spawned by the program. If ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined, the ACE library creates a static, singleton ACE_Object_Manager instance. The instance is placed in global program data, and constructed via a static object constructor. If ACE_HAS_NONSTATIC_OBJECT_MANAGER is defined, the ACE_Object_Manager instance is created on the stack of the main program thread, as noted above.
With ACE_HAS_NONSTATIC_OBJECT_MANAGER enabled, the ACE library has no static objects that require destruction. However, there are two drawbacks to using it: 1) main (int, char *[]) must be declared with arguments, even if they're not used. All of ACE is converted to this, so just applications have to be concerned with it. 2) If there any static objects that depend on those that are cleaned up by the Object_Manager, they'll get cleaned up too late. The ACE tests do not violate this requirement. However, applications may have trouble with it. NOTE on the use of <exit> -- <exit> does not destroy automatic objects. Therefore, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is enabled, the ACE_Object_Manager instance will *not* be destroyed if <exit> is called! However, <ACE_OS::exit> will properly destroy the ACE_Object_Manager. It is highly recommended that <ACE_OS::exit> be used instead of <exit>.
However, <exit> and <ACE_OS::exit> are tricky to use properly, especially in multithread programs. It is much safer to throw an exception (or simulate that effect) that will be caught by <main> instead of calling exit. Then, <main> can perform any necessary application-specific cleanup and return the status value. In addition, it's usually best to avoid calling <exit> and <ACE_OS::exit> from threads other than the main thread. Thanks to Jeff Greif <jmg@trivida.com> for pointing out that <exit> doesn't destroy automatic objects, and for developing the recommendations in this paragraph.
Instead of creating a static ACE_Object_Manager, or letting ACE create it on the stack of <main> for you, another alternative is to define ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER. With that define, the application must create the ACE_Object_Manager. The recommended way is to call <ACE::init> at the start of the program, and call <ACE::fini> at the end. Alternatively, the application could explicity construct an ACE_Object_Manager.
Definition at line 198 of file Object_Manager.h.
Unique identifiers for preallocated arrays. Please see ace/Managed_Object.h for information on accessing preallocated arrays.
| ACE_EMPTY_PREALLOCATED_ARRAY |
There currently are no preallocated arrays in the ACE library. If the application doesn't have any, make sure the the preallocated_array size is at least one by declaring this dummy . . . |
| ACE_PREALLOCATED_ARRAYS |
Hook for preallocated arrays provided by application. |
Definition at line 315 of file Object_Manager.h.
00316 { 00317 /// There currently are no preallocated arrays in the ACE 00318 /// library. If the application doesn't have any, make sure 00319 /// the the preallocated_array size is at least one by declaring 00320 /// this dummy . . . 00321 ACE_EMPTY_PREALLOCATED_ARRAY, 00322 00323 /// Hook for preallocated arrays provided by application. 00324 ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS 00325 00326 ACE_PREALLOCATED_ARRAYS // This enum value must be last! 00327 };
Unique identifiers for preallocated objects. Please see ace/Managed_Object.h for information on accessing preallocated objects.
Definition at line 286 of file Object_Manager.h.
00287 { 00288 ACE_FILECACHE_LOCK, 00289 #if defined (ACE_HAS_THREADS) 00290 ACE_STATIC_OBJECT_LOCK, 00291 #endif /* ACE_HAS_THREADS */ 00292 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00293 ACE_MT_CORBA_HANDLER_LOCK, 00294 ACE_DUMP_LOCK, 00295 ACE_SIG_HANDLER_LOCK, 00296 ACE_SINGLETON_NULL_LOCK, 00297 ACE_SINGLETON_RECURSIVE_THREAD_LOCK, 00298 ACE_THREAD_EXIT_LOCK, 00299 #if !defined (ACE_LACKS_ACE_TOKEN) 00300 ACE_TOKEN_MANAGER_CREATION_LOCK, 00301 ACE_TOKEN_INVARIANTS_CREATION_LOCK, 00302 #endif /* ! ACE_LACKS_ACE_TOKEN */ 00303 ACE_PROACTOR_EVENT_LOOP_LOCK, 00304 #endif /* ACE_MT_SAFE */ 00305 00306 // Hook for preallocated objects provided by application. 00307 ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS 00308 00309 ACE_PREALLOCATED_OBJECTS // This enum value must be last! 00310 };
| ACE_Object_Manager::ACE_Object_Manager | ( | void | ) |
Definition at line 378 of file Object_Manager.cpp.
00381 : exit_info_ () 00382 #if !defined (ACE_LACKS_ACE_SVCCONF) 00383 , preallocations_ (0) 00384 , ace_service_config_sig_handler_ (0) 00385 #endif /* ! ACE_LACKS_ACE_SVCCONF */ 00386 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00387 , singleton_null_lock_ (0) 00388 , singleton_recursive_lock_ (0) 00389 #endif /* ACE_MT_SAFE */ 00390 #if defined (ACE_HAS_TSS_EMULATION) 00391 , ts_storage_initialized_ (false) 00392 #endif 00393 { 00394 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00395 ACE_NEW (internal_lock_, ACE_Recursive_Thread_Mutex); 00396 # endif /* ACE_MT_SAFE */ 00397 00398 // If instance_ was not 0, then another ACE_Object_Manager has 00399 // already been instantiated (it is likely to be one initialized by way 00400 // of library/DLL loading). Let this one go through construction in 00401 // case there really is a good reason for it (like, ACE is a static/archive 00402 // library, and this one is the non-static instance (with 00403 // ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has a good reason for 00404 // creating a separate one) but the original one will be the one retrieved 00405 // from calls to ACE_Object_Manager::instance(). 00406 00407 // Be sure that no further instances are created via instance (). 00408 if (instance_ == 0) 00409 instance_ = this; 00410 00411 init (); 00412 }
| ACE_Object_Manager::~ACE_Object_Manager | ( | void | ) |
Definition at line 414 of file Object_Manager.cpp.
00415 { 00416 dynamically_allocated_ = false; // Don't delete this again in fini() 00417 fini (); 00418 }
| ACE_Object_Manager::ACE_Object_Manager | ( | const ACE_Object_Manager & | ) | [private] |
| int ACE_Object_Manager::at_exit | ( | void * | object, | |
| ACE_CLEANUP_FUNC | cleanup_hook, | |||
| void * | param, | |||
| const char * | name = 0 | |||
| ) | [static] |
Register an object (or array) for cleanup at process termination. "cleanup_hook" points to a (global, or static member) function that is called for the object or array when it to be destroyed. It may perform any necessary cleanup specific for that object or its class. "param" is passed as the second parameter to the cleanup_hook function; the first parameter is the object (or array) to be destroyed. cleanup_hook, for example, may delete the object (or array). For OS's that do not have processes, this function is the same as <at_thread_exit>. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered.
Definition at line 22 of file Object_Manager.inl.
00026 { 00027 return ACE_Object_Manager::instance ()->at_exit_i ( 00028 object, 00029 cleanup_hook, 00030 param, 00031 name); 00032 }
| int ACE_Object_Manager::at_exit | ( | ACE_Cleanup * | object, | |
| void * | param = 0, |
|||
| const char * | name = 0 | |||
| ) | [static] |
Register an ACE_Cleanup object for cleanup at process termination. The object is deleted via the <ace_cleanup_destroyer>. If you need more flexiblity, see the other at_exit method below. For OS's that do not have processes, cleanup takes place at the end of <main>. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered.
Definition at line 9 of file Object_Manager.inl.
00012 { 00013 return ACE_Object_Manager::instance ()->at_exit_i ( 00014 object, 00015 (ACE_CLEANUP_FUNC) ACE_CLEANUP_DESTROYER_NAME, 00016 param, 00017 name); 00018 }
| int ACE_Object_Manager::at_exit_i | ( | void * | object, | |
| ACE_CLEANUP_FUNC | cleanup_hook, | |||
| void * | param, | |||
| const char * | name | |||
| ) | [private] |
Register an object or array for deletion at program termination. See description of static version above for return values.
Definition at line 445 of file Object_Manager.cpp.
00449 { 00450 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00451 *instance_->internal_lock_, -1)); 00452 00453 if (shutting_down_i ()) 00454 { 00455 errno = EAGAIN; 00456 return -1; 00457 } 00458 00459 if (exit_info_.find (object)) 00460 { 00461 // The object has already been registered. 00462 errno = EEXIST; 00463 return -1; 00464 } 00465 00466 return exit_info_.at_exit_i (object, cleanup_hook, param, name); 00467 }
| static int ACE_Object_Manager::at_thread_exit | ( | void * | object, | |
| ACE_CLEANUP_FUNC | cleanup_hook, | |||
| void * | param, | |||
| const char * | name | |||
| ) | [static] |
Similar to <at_exit>, except that the cleanup_hook is called when the current thread exits instead of when the program terminates.
| ACE_Sig_Set & ACE_Object_Manager::default_mask | ( | void | ) | [static] |
Definition at line 43 of file Object_Manager.inl.
00044 { 00045 // A safe cast, but this static method shouldn't be used anyways. 00046 // Use ACE_Object_Manager::default_mask () instead. 00047 return 00048 *reinterpret_cast<ACE_Sig_Set *> (ACE_OS_Object_Manager::default_mask ()); 00049 }
| int ACE_Object_Manager::fini | ( | void | ) | [virtual] |
Explicitly destroy the singleton instance of the ACE_Object_Manager. Returns 0 on success, -1 on failure, and 1 if it had already been called.
Implements ACE_Object_Manager_Base.
Definition at line 710 of file Object_Manager.cpp.
00711 { 00712 if (shutting_down_i ()) 00713 // Too late. Or, maybe too early. Either fini () has already 00714 // been called, or init () was never called. 00715 return object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1; 00716 00717 // No mutex here. Only the main thread should destroy the singleton 00718 // ACE_Object_Manager instance. 00719 00720 // Indicate that this ACE_Object_Manager instance is being 00721 // shut down. 00722 object_manager_state_ = OBJ_MAN_SHUTTING_DOWN; 00723 00724 // Call all registered cleanup hooks, in reverse order of 00725 // registration. 00726 exit_info_.call_hooks (); 00727 00728 if (this == instance_) 00729 { 00730 #if !defined (ACE_LACKS_ACE_SVCCONF) 00731 delete preallocations_; 00732 preallocations_ = 0; 00733 #endif /* ! ACE_LACKS_ACE_SVCCONF */ 00734 00735 #if defined (ACE_HAS_TRACE) 00736 ACE_Trace::stop_tracing (); 00737 #endif /* ACE_HAS_TRACE */ 00738 00739 #if !defined (ACE_LACKS_ACE_SVCCONF) 00740 // Close and possibly delete all service instances in the Service 00741 // Repository. 00742 ACE_Service_Config::fini_svcs (); 00743 00744 // Unlink all services in the Service Repository and close/delete 00745 // all ACE library services and singletons. 00746 ACE_Service_Config::close (); 00747 #endif /* ! ACE_LACKS_ACE_SVCCONF */ 00748 00749 // This must come after closing ACE_Service_Config, since it will 00750 // close down it's dlls--it manages ACE_DLL_Manager. 00751 ACE_Framework_Repository::close_singleton (); 00752 ACE_DLL_Manager::close_singleton (); 00753 00754 # if ! defined (ACE_THREAD_MANAGER_LACKS_STATICS) 00755 ACE_Thread_Manager::close_singleton (); 00756 # endif /* ! ACE_THREAD_MANAGER_LACKS_STATICS */ 00757 00758 // Close the main thread's TSS, including its Log_Msg instance. 00759 ACE_OS::cleanup_tss (1 /* main thread */); 00760 00761 // 00762 // Note: Do not access Log Msg after this since it is gone 00763 // 00764 00765 // Close the ACE_Allocator. 00766 ACE_Allocator::close_singleton (); 00767 00768 #if ! defined (ACE_HAS_STATIC_PREALLOCATION) 00769 // Hooks for deletion of preallocated objects and arrays provided by 00770 // application. 00771 ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS 00772 ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS 00773 00774 // Cleanup the dynamically preallocated arrays. 00775 // (none) 00776 00777 // Cleanup the dynamically preallocated objects. 00778 ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) 00779 #if defined (ACE_HAS_THREADS) 00780 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, 00781 ACE_STATIC_OBJECT_LOCK) 00782 #endif /* ACE_HAS_THREADS */ 00783 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00784 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, 00785 ACE_MT_CORBA_HANDLER_LOCK) 00786 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) 00787 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, 00788 ACE_SIG_HANDLER_LOCK) 00789 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex, 00790 ACE_SINGLETON_NULL_LOCK) 00791 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, 00792 ACE_SINGLETON_RECURSIVE_THREAD_LOCK) 00793 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) 00794 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY) 00795 ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, 00796 ACE_TOKEN_MANAGER_CREATION_LOCK) 00797 ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, 00798 ACE_TOKEN_INVARIANTS_CREATION_LOCK) 00799 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */ 00800 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, 00801 ACE_PROACTOR_EVENT_LOOP_LOCK) 00802 # endif /* ACE_MT_SAFE */ 00803 #endif /* ! ACE_HAS_STATIC_PREALLOCATION */ 00804 00805 #if defined (ACE_HAS_THREADS) 00806 ACE_Static_Object_Lock::cleanup_lock (); 00807 #endif /* ACE_HAS_THREADS */ 00808 } 00809 00810 #if !defined (ACE_LACKS_ACE_SVCCONF) 00811 delete ace_service_config_sig_handler_; 00812 ace_service_config_sig_handler_ = 0; 00813 #endif /* ! ACE_LACKS_ACE_SVCCONF */ 00814 00815 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00816 delete internal_lock_; 00817 internal_lock_ = 0; 00818 00819 delete singleton_null_lock_; 00820 singleton_null_lock_ = 0; 00821 00822 delete singleton_recursive_lock_; 00823 singleton_recursive_lock_ = 0; 00824 #endif /* ACE_MT_SAFE */ 00825 00826 // Indicate that this ACE_Object_Manager instance has been shut down. 00827 object_manager_state_ = OBJ_MAN_SHUT_DOWN; 00828 00829 // Then, ensure that the ACE_OS_Object_Manager gets shut down. 00830 if (this == instance_ && ACE_OS_Object_Manager::instance_) 00831 ACE_OS_Object_Manager::instance_->fini (); 00832 00833 if (dynamically_allocated_) 00834 { 00835 delete this; 00836 } 00837 00838 if (this == instance_) 00839 instance_ = 0; 00840 00841 return 0; 00842 }
| static int ACE_Object_Manager::get_singleton_lock | ( | ACE_RW_Thread_Mutex *& | ) | [static] |
Accesses a readers/writer ACE_RW_Thread_Mutex to be used for construction of ACE_Singletons. Returns 0, and the lock in the argument, on success; returns -1 on failure.
| static int ACE_Object_Manager::get_singleton_lock | ( | ACE_Recursive_Thread_Mutex *& | ) | [static] |
Accesses a recursive ACE_Recursive_Thread_Mutex to be used for construction of ACE_Singletons. Returns 0, and the lock in the argument, on success; returns -1 on failure.
| static int ACE_Object_Manager::get_singleton_lock | ( | ACE_Mutex *& | ) | [static] |
Accesses a non-recursive ACE_Mutex to be used for construction of ACE_Singletons. Returns 0, and the lock in the argument, on success; returns -1 on failure.
| static int ACE_Object_Manager::get_singleton_lock | ( | ACE_Thread_Mutex *& | ) | [static] |
Accesses a non-recursive ACE_Thread_Mutex to be used for construction of ACE_Singletons. Returns 0, and the lock in the argument, on success; returns -1 on failure.
| static int ACE_Object_Manager::get_singleton_lock | ( | ACE_Null_Mutex *& | ) | [static] |
Accesses an ACE_Null_Mutex to be used for construction of ACE_Singletons. Returns 0, and the lock in the argument, on success; returns -1 on failure.
| int ACE_Object_Manager::init | ( | void | ) | [virtual] |
Explicitly initialize (construct the singleton instance of) the ACE_Object_Manager. Returns 0 on success, -1 on failure, and 1 if it had already been called.
Implements ACE_Object_Manager_Base.
Definition at line 193 of file Object_Manager.cpp.
00194 { 00195 if (starting_up_i ()) 00196 { 00197 // First, indicate that the ACE_Object_Manager instance is being 00198 // initialized. 00199 object_manager_state_ = OBJ_MAN_INITIALIZING; 00200 00201 // Only The Instance sets up with ACE_OS_Object_Manager and initializes 00202 // the preallocated objects. 00203 if (this == instance_) 00204 { 00205 // Make sure that the ACE_OS_Object_Manager has been created, 00206 // and register with it for chained fini (). 00207 ACE_OS_Object_Manager::instance ()->next_ = this; 00208 00209 # if defined (ACE_HAS_BUILTIN_ATOMIC_OP) 00210 ACE_Atomic_Op<ACE_Thread_Mutex, long>::init_functions (); 00211 ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::init_functions (); 00212 # endif /* ACE_HAS_BUILTIN_ATOMIC_OP */ 00213 00214 # if !defined (ACE_LACKS_ACE_SVCCONF) 00215 // Construct the ACE_Service_Config's signal handler. 00216 ACE_NEW_RETURN (ace_service_config_sig_handler_, 00217 ACE_Sig_Adapter (&ACE_Service_Config::handle_signal), -1); 00218 ACE_Service_Config::signal_handler (ace_service_config_sig_handler_); 00219 # endif /* ! ACE_LACKS_ACE_SVCCONF */ 00220 00221 // Allocate the preallocated (hard-coded) object instances. 00222 ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) 00223 # if defined (ACE_HAS_THREADS) 00224 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, 00225 ACE_STATIC_OBJECT_LOCK) 00226 # endif /* ACE_HAS_THREADS */ 00227 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00228 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, 00229 ACE_MT_CORBA_HANDLER_LOCK) 00230 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) 00231 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, 00232 ACE_SIG_HANDLER_LOCK) 00233 ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK) 00234 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, 00235 ACE_SINGLETON_RECURSIVE_THREAD_LOCK) 00236 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) 00237 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY) 00238 ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, 00239 ACE_TOKEN_MANAGER_CREATION_LOCK) 00240 ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, 00241 ACE_TOKEN_INVARIANTS_CREATION_LOCK) 00242 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */ 00243 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, 00244 ACE_PROACTOR_EVENT_LOOP_LOCK) 00245 # endif /* ACE_MT_SAFE */ 00246 } 00247 00248 if (this == instance_) 00249 { 00250 // Hooks for preallocated objects and arrays provided by application. 00251 ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS 00252 ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS 00253 00254 # if defined (ACE_HAS_TSS_EMULATION) 00255 // Initialize the main thread's TS storage. 00256 if (!ts_storage_initialized_) 00257 { 00258 ACE_TSS_Emulation::tss_open (ts_storage_); 00259 ts_storage_initialized_ = true; 00260 } 00261 # endif /* ACE_HAS_TSS_EMULATION */ 00262 00263 #if defined (ACE_DISABLE_WIN32_ERROR_WINDOWS) && \ 00264 defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00265 #if defined (_DEBUG) && (defined (_MSC_VER) || defined (__INTEL_COMPILER)) 00266 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); 00267 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); 00268 _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); 00269 _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); 00270 #endif /* _DEBUG && _MSC_VER || __INTEL_COMPILER */ 00271 00272 // The system does not display the critical-error-handler message box 00273 SetErrorMode(SEM_FAILCRITICALERRORS); 00274 00275 // And this will catch all unhandled exceptions. 00276 SetUnhandledExceptionFilter (&ACE_UnhandledExceptionFilter); 00277 00278 # if (_MSC_VER >= 1400) // VC++ 8.0 and above. 00279 // And this will stop the abort system call from being treated as a crash 00280 _set_abort_behavior( 0, _CALL_REPORTFAULT); 00281 00282 // Note the following fix was derived from that proposed by Jochen Kalmbach 00283 // http://blog.kalmbachnet.de/?postid=75 00284 // See also: 00285 // http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101337 00286 // 00287 // Starting with VC8 (VS2005), Microsoft changed the behaviour of the CRT in some 00288 // security related and special situations. The are many situations in which our 00289 // ACE_UnhandledExceptionFilter will never be called. This is a major change to 00290 // the previous versions of the CRT and is not very well documented. 00291 // The CRT simply forces the call to the default-debugger without informing the 00292 // registered unhandled exception filter. Jochen's solution is to stop the CRT 00293 // from calling SetUnhandledExceptionFilter() after we have done so above. 00294 // NOTE this only works for intel based windows builds. 00295 00296 # ifdef _M_IX86 00297 HMODULE hKernel32 = ACE_TEXT_LoadLibrary (ACE_TEXT ("kernel32.dll")); 00298 if (hKernel32) 00299 { 00300 void *pOrgEntry = 00301 GetProcAddress (hKernel32, "SetUnhandledExceptionFilter"); 00302 if (pOrgEntry) 00303 { 00304 unsigned char newJump[ 100 ]; 00305 DWORD dwOrgEntryAddr = reinterpret_cast<DWORD> (pOrgEntry); 00306 dwOrgEntryAddr += 5; // add 5 for 5 op-codes for jmp far 00307 void *pNewFunc = &ACEdisableSetUnhandledExceptionFilter; 00308 DWORD dwNewEntryAddr = reinterpret_cast<DWORD> (pNewFunc); 00309 DWORD dwRelativeAddr = dwNewEntryAddr - dwOrgEntryAddr; 00310 00311 newJump[ 0 ] = 0xE9; // JMP absolute 00312 ACE_OS::memcpy (&newJump[ 1 ], &dwRelativeAddr, sizeof (pNewFunc)); 00313 SIZE_T bytesWritten; 00314 WriteProcessMemory ( 00315 GetCurrentProcess (), 00316 pOrgEntry, 00317 newJump, 00318 sizeof (pNewFunc) + 1, 00319 &bytesWritten); 00320 } 00321 } 00322 # endif // _M_IX86 00323 # endif // (_MSC_VER >= 1400) // VC++ 8.0 and above. 00324 #endif /* ACE_DISABLE_WIN32_ERROR_WINDOWS && ACE_WIN32 && !ACE_HAS_WINCE */ 00325 00326 00327 # if !defined (ACE_LACKS_ACE_SVCCONF) 00328 ACE_NEW_RETURN (preallocations_, 00329 ACE_Object_Manager_Preallocations, 00330 -1); 00331 # endif /* ! ACE_LACKS_ACE_SVCCONF */ 00332 00333 // Open the main thread's ACE_Log_Msg. 00334 if (0 == ACE_LOG_MSG) 00335 return -1; 00336 } 00337 00338 // Finally, indicate that the ACE_Object_Manager instance has 00339 // been initialized. 00340 object_manager_state_ = OBJ_MAN_INITIALIZED; 00341 00342 #if defined (ACE_HAS_TRACE) 00343 // Allow tracing again (useful if user does init/fini/init) 00344 ACE_Trace::start_tracing (); 00345 #endif /* ACE_HAS_TRACE */ 00346 00347 return 0; 00348 } else { 00349 // Had already initialized. 00350 return 1; 00351 } 00352 }
| static int ACE_Object_Manager::init_tss | ( | void | ) | [static] |
| int ACE_Object_Manager::init_tss_i | ( | void | ) |
| ACE_Object_Manager * ACE_Object_Manager::instance | ( | void | ) | [static] |
Accessor to singleton instance. Because static member functions are provided in the interface, this should not be public. However, it is public so that ACE_Managed_Object<TYPE> can access it.
Definition at line 421 of file Object_Manager.cpp.
00422 { 00423 // This function should be called during construction of static 00424 // instances, or before any other threads have been created in 00425 // the process. So, it's not thread safe. 00426 00427 if (instance_ == 0) 00428 { 00429 ACE_Object_Manager *instance_pointer = 0; 00430 00431 ACE_NEW_RETURN (instance_pointer, 00432 ACE_Object_Manager, 00433 0); 00434 ACE_ASSERT (instance_pointer == instance_); 00435 00436 instance_pointer->dynamically_allocated_ = true; 00437 00438 return instance_pointer; 00439 } 00440 else 00441 return instance_; 00442 }
| ACE_Object_Manager& ACE_Object_Manager::operator= | ( | const ACE_Object_Manager & | ) | [private] |
Reimplemented from ACE_Object_Manager_Base.
| int ACE_Object_Manager::remove_at_exit | ( | void * | object | ) | [static] |
Definition at line 36 of file Object_Manager.inl.
00037 { 00038 return ACE_Object_Manager::instance ()->remove_at_exit_i (object); 00039 }
| int ACE_Object_Manager::remove_at_exit_i | ( | void * | object | ) | [private] |
Remove an object for deletion at program termination. See description of static version above for return values.
Definition at line 470 of file Object_Manager.cpp.
00471 { 00472 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, 00473 *instance_->internal_lock_, -1)); 00474 00475 if (shutting_down_i ()) 00476 { 00477 errno = EAGAIN; 00478 return -1; 00479 } 00480 00481 return exit_info_.remove (object); 00482 }
| int ACE_Object_Manager::shutting_down | ( | void | ) | [static] |
Returns 1 after the ACE_Object_Manager has been destroyed. This flag can be used to determine if the program is in the midst of destroying static objects. (Note that the program might destroy some static objects before this flag can return 1, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)
Definition at line 167 of file Object_Manager.cpp.
00168 { 00169 return ACE_Object_Manager::instance_ ? instance_->shutting_down_i () : 1; 00170 }
| int ACE_Object_Manager::starting_up | ( | void | ) | [static] |
Returns 1 before the ACE_Object_Manager has been constructed. This flag can be used to determine if the program is constructing static objects. If no static object spawns any threads, the program will be single-threaded when this flag returns 1. (Note that the program still might construct some static objects when this flag returns 0, if ACE_HAS_NONSTATIC_OBJECT_MANAGER is not defined.)
Definition at line 161 of file Object_Manager.cpp.
00162 { 00163 return ACE_Object_Manager::instance_ ? instance_->starting_up_i () : 1; 00164 }
friend class ACE_Object_Manager_Manager [friend] |
Definition at line 444 of file Object_Manager.h.
ACE_Service_Config signal handler.
Definition at line 345 of file Object_Manager.h.
For at_exit support.
Definition at line 338 of file Object_Manager.h.
ACE_Object_Manager * ACE_Object_Manager::instance_ = 0 [static, private] |
Singleton pointer.
Definition at line 423 of file Object_Manager.h.
Lock that is used to guard internal structures.
Definition at line 427 of file Object_Manager.h.
void * ACE_Object_Manager::preallocated_array = { 0 } [static] |
Table of preallocated arrays.
Definition at line 411 of file Object_Manager.h.
void * ACE_Object_Manager::preallocated_object = { 0 } [static] |
Table of preallocated objects.
Definition at line 408 of file Object_Manager.h.
Preallocated objects collection.
Definition at line 342 of file Object_Manager.h.
Null lock for guarding singleton creation.
Definition at line 430 of file Object_Manager.h.
ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex>* ACE_Object_Manager::singleton_recursive_lock_ [private] |
Lock for guarding singleton creation, when Object_Manager hasn't been started up, or has already been shut down.
Definition at line 434 of file Object_Manager.h.
void* ACE_Object_Manager::ts_storage_[ACE_TSS_Emulation::ACE_TSS_THREAD_KEYS_MAX] [private] |
Definition at line 439 of file Object_Manager.h.
bool ACE_Object_Manager::ts_storage_initialized_ [private] |
Definition at line 440 of file Object_Manager.h.
1.6.1