#include <Object_Manager.h>
Inheritance diagram for ACE_Object_Manager:


Public Types | |
| enum | Preallocated_Object { ACE_FILECACHE_LOCK, ACE_STATIC_OBJECT_LOCK, ACE_PREALLOCATED_OBJECTS } |
| Unique identifiers for preallocated objects. Please see ace/Managed_Object.h for information on accessing preallocated objects. More... | |
| enum | Preallocated_Array { ACE_EMPTY_PREALLOCATED_ARRAY, ACE_PREALLOCATED_ARRAYS } |
| Unique identifiers for preallocated arrays. Please see ace/Managed_Object.h for information on accessing preallocated arrays. More... | |
Public Methods | |
| virtual int | init (void) |
| virtual int | fini (void) |
| ACE_Object_Manager (void) | |
| ~ACE_Object_Manager (void) | |
Static Public Methods | |
| int | starting_up (void) |
| int | shutting_down (void) |
| int | at_exit (ACE_Cleanup *object, void *param=0) |
| int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
| ACE_Sig_Set & | default_mask (void) |
| ACE_Object_Manager * | instance (void) |
Static Public Attributes | |
| void * | preallocated_object [ACE_PREALLOCATED_OBJECTS] = { 0 } |
| Table of preallocated objects. More... | |
| void * | preallocated_array [ACE_PREALLOCATED_ARRAYS] = { 0 } |
| Table of preallocated arrays. More... | |
Private Methods | |
| int | at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
| Register an object or array for deletion at program termination. See description of static version above for return values. More... | |
| ACE_Object_Manager (const ACE_Object_Manager &) | |
| ACE_Object_Manager & | operator= (const ACE_Object_Manager &) |
Private Attributes | |
| ACE_OS_Exit_Info | exit_info_ |
| For at_exit support. More... | |
| ACE_Object_Manager_Preallocations * | preallocations_ |
| Preallocated objects collection. More... | |
| ACE_Sig_Adapter * | ace_service_config_sig_handler_ |
| ACE_Service_Config signal handler. More... | |
Static Private Attributes | |
| ACE_Object_Manager * | instance_ = 0 |
| Singleton pointer. More... | |
Friends | |
| class | ACE_Object_Manager_Manager |
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 177 of file Object_Manager.h.
|
|
Unique identifiers for preallocated arrays. Please see ace/Managed_Object.h for information on accessing preallocated arrays.
Definition at line 285 of file Object_Manager.h. Referenced by ACE_Managed_Object::get_preallocated_array.
00286 {
00287 /// There currently are no preallocated arrays in the ACE
00288 /// library. If the application doesn't have any, make sure
00289 /// the the preallocated_array size is at least one by declaring
00290 /// this dummy . . .
00291 ACE_EMPTY_PREALLOCATED_ARRAY,
00292
00293 /// Hook for preallocated arrays provided by application.
00294 ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS
00295
00296 ACE_PREALLOCATED_ARRAYS // This enum value must be last!
00297 };
|
|
|
Unique identifiers for preallocated objects. Please see ace/Managed_Object.h for information on accessing preallocated objects.
Definition at line 256 of file Object_Manager.h. Referenced by ACE_Managed_Object::get_preallocated_object.
00257 {
00258 ACE_FILECACHE_LOCK,
00259 #if defined (ACE_HAS_THREADS)
00260 ACE_STATIC_OBJECT_LOCK,
00261 #endif /* ACE_HAS_THREADS */
00262 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00263 ACE_MT_CORBA_HANDLER_LOCK,
00264 ACE_DUMP_LOCK,
00265 ACE_SIG_HANDLER_LOCK,
00266 ACE_SINGLETON_NULL_LOCK,
00267 ACE_SINGLETON_RECURSIVE_THREAD_LOCK,
00268 ACE_THREAD_EXIT_LOCK,
00269 #if !defined (ACE_LACKS_ACE_TOKEN)
00270 ACE_TOKEN_MANAGER_CREATION_LOCK,
00271 ACE_TOKEN_INVARIANTS_CREATION_LOCK,
00272 #endif /* ! ACE_LACKS_ACE_TOKEN */
00273 ACE_PROACTOR_EVENT_LOOP_LOCK,
00274 #endif /* ACE_MT_SAFE */
00275
00276 // Hook for preallocated objects provided by application.
00277 ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS
00278
00279 ACE_PREALLOCATED_OBJECTS // This enum value must be last!
00280 };
|
|
|
Definition at line 276 of file Object_Manager.cpp. References ACE_NEW.
00279 : exit_info_ () 00280 #if !defined (ACE_LACKS_ACE_SVCCONF) 00281 , preallocations_ (0) 00282 , ace_service_config_sig_handler_ (0) 00283 #endif /* ! ACE_LACKS_ACE_SVCCONF */ 00284 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00285 , singleton_null_lock_ (0) 00286 , singleton_recursive_lock_ (0) 00287 # endif /* ACE_MT_SAFE */ 00288 { 00289 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00290 ACE_NEW (internal_lock_, ACE_Recursive_Thread_Mutex); 00291 # endif /* ACE_MT_SAFE */ 00292 00293 // If instance_ was not 0, then another ACE_Object_Manager has 00294 // already been instantiated (it is likely to be one initialized by way 00295 // of library/DLL loading). Let this one go through construction in 00296 // case there really is a good reason for it (like, ACE is a static/archive 00297 // library, and this one is the non-static instance (with 00298 // ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has a good reason for 00299 // creating a separate one) but the original one will be the one retrieved 00300 // from calls to ACE_Object_Manager::instance(). 00301 00302 // Be sure that no further instances are created via instance (). 00303 if (instance_ == 0) 00304 instance_ = this; 00305 00306 init (); 00307 } |
|
|
Definition at line 309 of file Object_Manager.cpp. References ACE_Object_Manager_Base::dynamically_allocated_, and fini.
00310 {
00311 dynamically_allocated_ = 0; // Don't delete this again in fini()
00312 fini ();
00313 }
|
|
|
|
|
||||||||||||||||
|
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 17 of file Object_Manager.i. References ACE_CLEANUP_FUNC, at_exit_i, and instance.
00020 {
00021 return ACE_Object_Manager::instance ()->at_exit_i (
00022 object,
00023 cleanup_hook,
00024 param);
00025 }
|
|
||||||||||||
|
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 6 of file Object_Manager.i. References ACE_CLEANUP_FUNC, at_exit_i, and instance. Referenced by ACE_Token_Manager::instance, ACE_Token_Invariant_Manager::instance, ACE_TSS_Singleton::instance, ACE_Singleton::instance, ACE_Process_Manager::instance, and ACE_Log_Msg::instance.
00008 {
00009 return ACE_Object_Manager::instance ()->at_exit_i (
00010 object,
00011 (ACE_CLEANUP_FUNC) ace_cleanup_destroyer,
00012 param);
00013 }
|
|
||||||||||||||||
|
Register an object or array for deletion at program termination. See description of static version above for return values.
Definition at line 340 of file Object_Manager.cpp. References ACE_CLEANUP_FUNC, ACE_GUARD_RETURN, ACE_MT, ACE_OS_Exit_Info::at_exit_i, exit_info_, ACE_OS_Exit_Info::find, instance_, and ACE_Object_Manager_Base::shutting_down_i. Referenced by at_exit.
00343 {
00344 ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00345 *instance_->internal_lock_, -1));
00346
00347 if (shutting_down_i ())
00348 {
00349 errno = EAGAIN;
00350 return -1;
00351 }
00352
00353 if (exit_info_.find (object))
00354 {
00355 // The object has already been registered.
00356 errno = EEXIST;
00357 return -1;
00358 }
00359
00360 return exit_info_.at_exit_i (object, cleanup_hook, param);
00361 }
|
|
|
Definition at line 29 of file Object_Manager.i. References ACE_OS_Object_Manager::default_mask.
00030 {
00031 // A safe cast, but this static method shouldn't be used anyways.
00032 // Use ACE_Object_Manager::default_mask () instead.
00033 return *ACE_reinterpret_cast (ACE_Sig_Set *,
00034 ACE_OS_Object_Manager::default_mask ());
00035 }
|
|
|
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 591 of file Object_Manager.cpp. References ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS, ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS, ACE_DELETE_PREALLOCATED_OBJECT, ACE_FILECACHE_LOCK, ace_service_config_sig_handler_, ACE_STATIC_OBJECT_LOCK, ACE_SYNCH_RW_MUTEX, ACE_OS_Exit_Info::call_hooks, ACE_Static_Object_Lock::cleanup_lock, ACE_OS::cleanup_tss, ACE_Service_Config::close, ACE_Allocator::close_singleton, ACE_Thread_Manager::close_singleton, ACE_Framework_Repository::close_singleton, exit_info_, ACE_OS_Object_Manager::fini, ACE_Service_Config::fini_svcs, ACE_OS_Object_Manager::instance_, instance_, ACE_TOKEN_CONST::MUTEX, ACE_Object_Manager_Base::OBJ_MAN_SHUT_DOWN, ACE_Object_Manager_Base::OBJ_MAN_SHUTTING_DOWN, ACE_Object_Manager_Base::object_manager_state_, preallocations_, ACE_Object_Manager_Base::shutting_down_i, and ACE_Trace::stop_tracing. Referenced by ACE_Init_ACE::fini, and ~ACE_Object_Manager.
00592 {
00593 if (shutting_down_i ())
00594 // Too late. Or, maybe too early. Either fini () has already
00595 // been called, or init () was never called.
00596 return object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1;
00597
00598 // No mutex here. Only the main thread should destroy the singleton
00599 // ACE_Object_Manager instance.
00600
00601 // First, indicate that this ACE_Object_Manager instance is being
00602 // shut down.
00603 object_manager_state_ = OBJ_MAN_SHUTTING_DOWN;
00604
00605 // Call all registered cleanup hooks, in reverse order of
00606 // registration.
00607 exit_info_.call_hooks ();
00608
00609 if (this == instance_)
00610 {
00611 #if !defined (ACE_LACKS_ACE_SVCCONF)
00612 delete preallocations_;
00613 preallocations_ = 0;
00614 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00615
00616 ACE_Trace::stop_tracing ();
00617
00618 #if !defined (ACE_LACKS_ACE_SVCCONF)
00619 // Close and possibly delete all service instances in the Service
00620 // Repository.
00621 ACE_Service_Config::fini_svcs ();
00622
00623 // Unlink all services in the Service Repository and close/delete
00624 // all ACE library services and singletons.
00625 ACE_Service_Config::close ();
00626 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00627
00628 // This must come after closing ACE_Service_Config, since it will
00629 // close down it's dlls--it manages ACE_DLL_Manager.
00630 ACE_Framework_Repository::close_singleton ();
00631
00632 # if ! defined (ACE_THREAD_MANAGER_LACKS_STATICS)
00633 ACE_Thread_Manager::close_singleton ();
00634 # endif /* ! ACE_THREAD_MANAGER_LACKS_STATICS */
00635
00636 // Close the main thread's TSS, including its Log_Msg instance.
00637 ACE_OS::cleanup_tss (1 /* main thread */);
00638
00639 //
00640 // Note: Do not access Log Msg after this since it is gone
00641 //
00642
00643 // Close the ACE_Allocator.
00644 ACE_Allocator::close_singleton ();
00645
00646 #if ! defined (ACE_HAS_STATIC_PREALLOCATION)
00647 // Hooks for deletion of preallocated objects and arrays provided by
00648 // application.
00649 ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS
00650 ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS
00651
00652 // Cleanup the dynamically preallocated arrays.
00653 // (none)
00654
00655 // Cleanup the dynamically preallocated objects.
00656 ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
00657 #if defined (ACE_HAS_THREADS)
00658 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00659 ACE_STATIC_OBJECT_LOCK)
00660 #endif /* ACE_HAS_THREADS */
00661 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00662 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
00663 ACE_MT_CORBA_HANDLER_LOCK)
00664 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
00665 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00666 ACE_SIG_HANDLER_LOCK)
00667 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex,
00668 ACE_SINGLETON_NULL_LOCK)
00669 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00670 ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
00671 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
00672 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
00673 ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
00674 ACE_TOKEN_MANAGER_CREATION_LOCK)
00675 ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
00676 ACE_TOKEN_INVARIANTS_CREATION_LOCK)
00677 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
00678 ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
00679 ACE_PROACTOR_EVENT_LOOP_LOCK)
00680 # endif /* ACE_MT_SAFE */
00681 #endif /* ! ACE_HAS_STATIC_PREALLOCATION */
00682
00683 #if defined (ACE_HAS_THREADS)
00684 ACE_Static_Object_Lock::cleanup_lock ();
00685 #endif /* ACE_HAS_THREADS */
00686 }
00687
00688 #if !defined (ACE_LACKS_ACE_SVCCONF)
00689 delete ace_service_config_sig_handler_;
00690 ace_service_config_sig_handler_ = 0;
00691 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00692
00693 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00694 delete internal_lock_;
00695 internal_lock_ = 0;
00696
00697 delete singleton_null_lock_;
00698 singleton_null_lock_ = 0;
00699
00700 delete singleton_recursive_lock_;
00701 singleton_recursive_lock_ = 0;
00702 #endif /* ACE_MT_SAFE */
00703
00704 // Indicate that this ACE_Object_Manager instance has been shut down.
00705 object_manager_state_ = OBJ_MAN_SHUT_DOWN;
00706
00707 // Then, ensure that the ACE_OS_Object_Manager gets shut down.
00708 if (this == instance_ && ACE_OS_Object_Manager::instance_)
00709 ACE_OS_Object_Manager::instance_->fini ();
00710
00711 if (dynamically_allocated_)
00712 {
00713 delete this;
00714 }
00715
00716 if (this == instance_)
00717 instance_ = 0;
00718
00719 return 0;
00720 }
|
|
|
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 173 of file Object_Manager.cpp. References ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS, ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS, ACE_FILECACHE_LOCK, ACE_LOG_MSG, ACE_NEW_RETURN, ACE_PREALLOCATE_OBJECT, ace_service_config_sig_handler_, ACE_STATIC_OBJECT_LOCK, ACE_SYNCH_RW_MUTEX, ACE_Service_Config::handle_signal, ACE_OS_Object_Manager::instance, instance_, ACE_TOKEN_CONST::MUTEX, ACE_Object_Manager_Base::next_, ACE_Object_Manager_Base::OBJ_MAN_INITIALIZED, ACE_Object_Manager_Base::OBJ_MAN_INITIALIZING, ACE_Object_Manager_Base::object_manager_state_, preallocations_, ACE_Service_Config::signal_handler, ACE_Trace::start_tracing, and ACE_Object_Manager_Base::starting_up_i. Referenced by ACE_Init_ACE::init.
00174 {
00175 if (starting_up_i ())
00176 {
00177 // First, indicate that the ACE_Object_Manager instance is being
00178 // initialized.
00179 object_manager_state_ = OBJ_MAN_INITIALIZING;
00180
00181 // Only The Instance sets up with ACE_OS_Object_Manager and initializes
00182 // the preallocated objects.
00183 if (this == instance_)
00184 {
00185 // Make sure that the ACE_OS_Object_Manager has been created,
00186 // and register with it for chained fini ().
00187 ACE_OS_Object_Manager::instance ()->next_ = this;
00188
00189 # if defined (ACE_HAS_BUILTIN_ATOMIC_OP)
00190 ACE_Atomic_Op<ACE_Thread_Mutex, long>::init_functions ();
00191 # endif /* ACE_HAS_BUILTIN_ATOMIC_OP */
00192
00193 # if !defined (ACE_LACKS_ACE_SVCCONF)
00194 // Construct the ACE_Service_Config's signal handler.
00195 ACE_NEW_RETURN (ace_service_config_sig_handler_,
00196 ACE_Sig_Adapter (&ACE_Service_Config::handle_signal), -1);
00197 ACE_Service_Config::signal_handler (ace_service_config_sig_handler_);
00198 # endif /* ! ACE_LACKS_ACE_SVCCONF */
00199
00200 // Allocate the preallocated (hard-coded) object instances.
00201 ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
00202 # if defined (ACE_HAS_THREADS)
00203 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00204 ACE_STATIC_OBJECT_LOCK)
00205 # endif /* ACE_HAS_THREADS */
00206 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00207 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
00208 ACE_MT_CORBA_HANDLER_LOCK)
00209 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
00210 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00211 ACE_SIG_HANDLER_LOCK)
00212 ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK)
00213 ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00214 ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
00215 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
00216 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
00217 ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
00218 ACE_TOKEN_MANAGER_CREATION_LOCK)
00219 ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
00220 ACE_TOKEN_INVARIANTS_CREATION_LOCK)
00221 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
00222 ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
00223 ACE_PROACTOR_EVENT_LOOP_LOCK)
00224 # endif /* ACE_MT_SAFE */
00225 }
00226
00227 if (this == instance_)
00228 {
00229 // Hooks for preallocated objects and arrays provided by application.
00230 ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS
00231 ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS
00232
00233 # if defined (ACE_HAS_TSS_EMULATION)
00234 // Initialize the main thread's TS storage.
00235 ACE_TSS_Emulation::tss_open (ts_storage_);
00236 # endif /* ACE_HAS_TSS_EMULATION */
00237
00238 #if defined (ACE_DISABLE_WIN32_ERROR_WINDOWS)
00239 #if defined (_DEBUG) && defined (_MSC_VER)
00240 // This will keep the ACE_Assert window
00241 _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
00242 _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
00243 #endif /* _DEBUG && _MSC_VER */
00244
00245 // And this will catch all unhandled exceptions.
00246 SetUnhandledExceptionFilter (&ACE_UnhandledExceptionFilter);
00247 #endif /* ACE_DISABLE_WIN32_ERROR_WINDOWS */
00248
00249
00250
00251 # if !defined (ACE_LACKS_ACE_SVCCONF)
00252 ACE_NEW_RETURN (preallocations_,
00253 ACE_Object_Manager_Preallocations,
00254 -1);
00255 # endif /* ! ACE_LACKS_ACE_SVCCONF */
00256
00257 // Open the main thread's ACE_Log_Msg.
00258 if (NULL == ACE_LOG_MSG)
00259 return -1;
00260 }
00261
00262 // Finally, indicate that the ACE_Object_Manager instance has
00263 // been initialized.
00264 object_manager_state_ = OBJ_MAN_INITIALIZED;
00265
00266 // Allow tracing again (useful if user does init/fini/init)
00267 ACE_Trace::start_tracing ();
00268
00269 return 0;
00270 } else {
00271 // Had already initialized.
00272 return 1;
00273 }
00274 }
|
|
|
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 316 of file Object_Manager.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_Object_Manager_Base::dynamically_allocated_, and instance_. Referenced by ACE_Object_Manager_Manager::ACE_Object_Manager_Manager, at_exit, ACE_Init_ACE::fini, and ACE_Init_ACE::init.
00317 {
00318 // This function should be called during construction of static
00319 // instances, or before any other threads have been created in
00320 // the process. So, it's not thread safe.
00321
00322 if (instance_ == 0)
00323 {
00324 ACE_Object_Manager *instance_pointer;
00325
00326 ACE_NEW_RETURN (instance_pointer,
00327 ACE_Object_Manager,
00328 0);
00329 ACE_ASSERT (instance_pointer == instance_);
00330
00331 instance_pointer->dynamically_allocated_ = 1;
00332
00333 return instance_pointer;
00334 }
00335 else
00336 return instance_;
00337 }
|
|
|
|
|
|
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 147 of file Object_Manager.cpp. References instance_, and ACE_Object_Manager_Base::shutting_down_i. Referenced by ACE_DLL_Singleton_T::instance, ACE_Unmanaged_TSS_Singleton::instance, ACE_TSS_Singleton::instance, ACE_Unmanaged_Singleton::instance, ACE_Singleton::instance, ACE_Service_Repository::instance, ACE_Static_Object_Lock::instance, ACE_Framework_Repository::instance, and ACE_Thread_Manager::wait.
00148 {
00149 return ACE_Object_Manager::instance_ ? instance_->shutting_down_i () : 1;
00150 }
|
|
|
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 141 of file Object_Manager.cpp. References instance_, and ACE_Object_Manager_Base::starting_up_i. Referenced by ACE_DLL_Singleton_T::instance, ACE_Unmanaged_TSS_Singleton::instance, ACE_TSS_Singleton::instance, ACE_Unmanaged_Singleton::instance, ACE_Singleton::instance, ACE_Service_Repository::instance, ACE_Static_Object_Lock::instance, and ACE_Framework_Repository::instance.
00142 {
00143 return ACE_Object_Manager::instance_ ? instance_->starting_up_i () : 1;
00144 }
|
|
|
Definition at line 409 of file Object_Manager.h. |
|
|
ACE_Service_Config signal handler.
Definition at line 315 of file Object_Manager.h. |
|
|
For at_exit support.
Definition at line 308 of file Object_Manager.h. |
|
|
Singleton pointer.
Definition at line 45 of file Object_Manager.cpp. Referenced by at_exit_i, fini, init, instance, shutting_down, starting_up, and ACE_Object_Manager_Manager::~ACE_Object_Manager_Manager. |
|
|
Table of preallocated arrays.
Definition at line 51 of file Object_Manager.cpp. Referenced by ACE_Managed_Object::get_preallocated_array. |
|
|
Table of preallocated objects.
Definition at line 48 of file Object_Manager.cpp. Referenced by ACE_Managed_Object::get_preallocated_object. |
|
|
Preallocated objects collection.
Definition at line 312 of file Object_Manager.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002