ACE_Object_Manager Class Reference

Manager for ACE library services and singleton cleanup. More...

#include <Object_Manager.h>

Inheritance diagram for ACE_Object_Manager:

Inheritance graph
[legend]
Collaboration diagram for ACE_Object_Manager:

Collaboration graph
[legend]
List of all members.

Public Types

enum  Preallocated_Object { ACE_FILECACHE_LOCK, ACE_STATIC_OBJECT_LOCK, ACE_PREALLOCATED_OBJECTS }
enum  Preallocated_Array { ACE_EMPTY_PREALLOCATED_ARRAY, ACE_PREALLOCATED_ARRAYS }

Public Member Functions

virtual int init (void)
virtual int fini (void)
 ACE_Object_Manager (void)
 ~ACE_Object_Manager (void)

Static Public Member Functions

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_Setdefault_mask (void)
ACE_Object_Managerinstance (void)

Static Public Attributes

void * preallocated_object [ACE_PREALLOCATED_OBJECTS] = { 0 }
 Table of preallocated objects.

void * preallocated_array [ACE_PREALLOCATED_ARRAYS] = { 0 }
 Table of preallocated arrays.


Private Member Functions

int at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param)
 ACE_Object_Manager (const ACE_Object_Manager &)
ACE_Object_Manageroperator= (const ACE_Object_Manager &)

Private Attributes

ACE_OS_Exit_Info exit_info_
 For at_exit support.

ACE_Object_Manager_Preallocationspreallocations_
 Preallocated objects collection.

ACE_Sig_Adapterace_service_config_sig_handler_
 ACE_Service_Config signal handler.


Static Private Attributes

ACE_Object_Managerinstance_ = 0
 Singleton pointer.


Friends

class ACE_Object_Manager_Manager

Detailed Description

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 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 instead of calling exit. Then, 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 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.


Member Enumeration Documentation

enum ACE_Object_Manager::Preallocated_Array
 

Unique identifiers for preallocated arrays. Please see ace/Managed_Object.h for information on accessing preallocated arrays.

Enumeration values:
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 306 of file Object_Manager.h.

00307     {
00308       /// There currently are no preallocated arrays in the ACE
00309       /// library.  If the application doesn't have any, make sure
00310       /// the the preallocated_array size is at least one by declaring
00311       /// this dummy . . .
00312       ACE_EMPTY_PREALLOCATED_ARRAY,
00313 
00314       /// Hook for preallocated arrays provided by application.
00315       ACE_APPLICATION_PREALLOCATED_ARRAY_DECLARATIONS
00316 
00317       ACE_PREALLOCATED_ARRAYS  // This enum value must be last!
00318     };

enum ACE_Object_Manager::Preallocated_Object
 

Unique identifiers for preallocated objects. Please see ace/Managed_Object.h for information on accessing preallocated objects.

Enumeration values:
ACE_FILECACHE_LOCK 
ACE_STATIC_OBJECT_LOCK 
ACE_PREALLOCATED_OBJECTS 

Definition at line 277 of file Object_Manager.h.

00278     {
00279       ACE_FILECACHE_LOCK,
00280 #if defined (ACE_HAS_THREADS)
00281       ACE_STATIC_OBJECT_LOCK,
00282 #endif /* ACE_HAS_THREADS */
00283 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00284       ACE_MT_CORBA_HANDLER_LOCK,
00285       ACE_DUMP_LOCK,
00286       ACE_SIG_HANDLER_LOCK,
00287       ACE_SINGLETON_NULL_LOCK,
00288       ACE_SINGLETON_RECURSIVE_THREAD_LOCK,
00289       ACE_THREAD_EXIT_LOCK,
00290 #if !defined (ACE_LACKS_ACE_TOKEN)
00291       ACE_TOKEN_MANAGER_CREATION_LOCK,
00292       ACE_TOKEN_INVARIANTS_CREATION_LOCK,
00293 #endif /* ! ACE_LACKS_ACE_TOKEN */
00294       ACE_PROACTOR_EVENT_LOOP_LOCK,
00295 #endif /* ACE_MT_SAFE */
00296 
00297       // Hook for preallocated objects provided by application.
00298       ACE_APPLICATION_PREALLOCATED_OBJECT_DECLARATIONS
00299 
00300       ACE_PREALLOCATED_OBJECTS  // This enum value must be last!
00301     };


Constructor & Destructor Documentation

ACE_Object_Manager::ACE_Object_Manager void   ) 
 

Definition at line 282 of file Object_Manager.cpp.

References ACE_NEW, init(), and instance_.

00285   : exit_info_ ()
00286 #if !defined (ACE_LACKS_ACE_SVCCONF)
00287   , preallocations_ (0)
00288   , ace_service_config_sig_handler_ (0)
00289 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00290 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00291   , singleton_null_lock_ (0)
00292   , singleton_recursive_lock_ (0)
00293 # endif /* ACE_MT_SAFE */
00294 {
00295 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00296   ACE_NEW (internal_lock_, ACE_Recursive_Thread_Mutex);
00297 # endif /* ACE_MT_SAFE */
00298 
00299   // If instance_ was not 0, then another ACE_Object_Manager has
00300   // already been instantiated (it is likely to be one initialized by way
00301   // of library/DLL loading).  Let this one go through construction in
00302   // case there really is a good reason for it (like, ACE is a static/archive
00303   // library, and this one is the non-static instance (with
00304   // ACE_HAS_NONSTATIC_OBJECT_MANAGER, or the user has a good reason for
00305   // creating a separate one) but the original one will be the one retrieved
00306   // from calls to ACE_Object_Manager::instance().
00307 
00308   // Be sure that no further instances are created via instance ().
00309   if (instance_ == 0)
00310     instance_ = this;
00311 
00312   init ();
00313 }

ACE_Object_Manager::~ACE_Object_Manager void   ) 
 

Definition at line 315 of file Object_Manager.cpp.

References fini().

00316 {
00317   dynamically_allocated_ = false;   // Don't delete this again in fini()
00318   fini ();
00319 }

ACE_Object_Manager::ACE_Object_Manager const ACE_Object_Manager  )  [private]
 


Member Function Documentation

ACE_INLINE int ACE_Object_Manager::at_exit void *  object,
ACE_CLEANUP_FUNC  cleanup_hook,
void *  param
[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 . 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 20 of file Object_Manager.inl.

References ACE_CLEANUP_FUNC, at_exit_i(), and instance().

00023 {
00024   return ACE_Object_Manager::instance ()->at_exit_i (
00025     object,
00026     cleanup_hook,
00027     param);
00028 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Object_Manager::at_exit ACE_Cleanup object,
void *  param = 0
[static]
 

Register an ACE_Cleanup object for cleanup at process termination. The object is deleted via the . If you need more flexiblity, see the method below. For OS's that do not have processes, cleanup takes place at the end of . 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.

References ACE_CLEANUP_DESTROYER_NAME, ACE_CLEANUP_FUNC, at_exit_i(), and instance().

Referenced by ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Process_Manager::instance(), and ACE_Log_Msg::instance().

00011 {
00012   return ACE_Object_Manager::instance ()->at_exit_i (
00013     object,
00014     (ACE_CLEANUP_FUNC) ACE_CLEANUP_DESTROYER_NAME,
00015     param);
00016 }

int ACE_Object_Manager::at_exit_i void *  object,
ACE_CLEANUP_FUNC  cleanup_hook,
void *  param
[private]
 

Register an object or array for deletion at program termination. See description of static version above for return values.

Definition at line 346 of file Object_Manager.cpp.

References ACE_CLEANUP_FUNC, ACE_GUARD_RETURN, 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().

00349 {
00350   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00351     *instance_->internal_lock_, -1));
00352 
00353   if (shutting_down_i ())
00354     {
00355       errno = EAGAIN;
00356       return -1;
00357     }
00358 
00359   if (exit_info_.find (object))
00360     {
00361       // The object has already been registered.
00362       errno = EEXIST;
00363       return -1;
00364     }
00365 
00366   return exit_info_.at_exit_i (object, cleanup_hook, param);
00367 }

ACE_INLINE ACE_Sig_Set & ACE_Object_Manager::default_mask void   )  [static]
 

Deprecated:
Accesses a default signal set used, for example, in ACE_Sig_Guard methods. Deprecated: use ACE_Object_Manager::default_mask () instead.

Definition at line 32 of file Object_Manager.inl.

References ACE_OS_Object_Manager::default_mask().

00033 {
00034   // A safe cast, but this static method shouldn't be used anyways.
00035   // Use ACE_Object_Manager::default_mask () instead.
00036   return
00037     *reinterpret_cast<ACE_Sig_Set *> (ACE_OS_Object_Manager::default_mask ());
00038 }

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 593 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_OS::cleanup_tss(), ACE_Service_Config::close(), ACE_Allocator::close_singleton(), ACE_Thread_Manager::close_singleton(), ACE_DLL_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_, preallocations_, ACE_Object_Manager_Base::shutting_down_i(), and ACE_Trace::stop_tracing().

Referenced by ACE::fini(), and ~ACE_Object_Manager().

00594 {
00595   if (shutting_down_i ())
00596     // Too late.  Or, maybe too early.  Either fini () has already
00597     // been called, or init () was never called.
00598     return object_manager_state_ == OBJ_MAN_SHUT_DOWN  ?  1  :  -1;
00599 
00600   // No mutex here.  Only the main thread should destroy the singleton
00601   // ACE_Object_Manager instance.
00602 
00603   // Indicate that this ACE_Object_Manager instance is being
00604   // shut down.
00605   object_manager_state_ = OBJ_MAN_SHUTTING_DOWN;
00606 
00607   // Call all registered cleanup hooks, in reverse order of
00608   // registration.
00609   exit_info_.call_hooks ();
00610 
00611   if (this == instance_)
00612     {
00613 #if !defined (ACE_LACKS_ACE_SVCCONF)
00614       delete preallocations_;
00615       preallocations_ = 0;
00616 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00617 
00618 #if defined (ACE_HAS_TRACE)
00619       ACE_Trace::stop_tracing ();
00620 #endif /* ACE_HAS_TRACE */
00621 
00622 #if !defined (ACE_LACKS_ACE_SVCCONF)
00623       // Close and possibly delete all service instances in the Service
00624       // Repository.
00625       ACE_Service_Config::fini_svcs ();
00626 
00627       // Unlink all services in the Service Repository and close/delete
00628       // all ACE library services and singletons.
00629       ACE_Service_Config::close ();
00630 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00631 
00632       // This must come after closing ACE_Service_Config, since it will
00633       // close down it's dlls--it manages ACE_DLL_Manager.
00634       ACE_Framework_Repository::close_singleton ();
00635       ACE_DLL_Manager::close_singleton ();
00636 
00637 #  if ! defined (ACE_THREAD_MANAGER_LACKS_STATICS)
00638       ACE_Thread_Manager::close_singleton ();
00639 #  endif /* ! ACE_THREAD_MANAGER_LACKS_STATICS */
00640 
00641       // Close the main thread's TSS, including its Log_Msg instance.
00642       ACE_OS::cleanup_tss (1 /* main thread */);
00643 
00644       //
00645       // Note:  Do not access Log Msg after this since it is gone
00646       //
00647 
00648       // Close the ACE_Allocator.
00649       ACE_Allocator::close_singleton ();
00650 
00651 #if ! defined (ACE_HAS_STATIC_PREALLOCATION)
00652       // Hooks for deletion of preallocated objects and arrays provided by
00653       // application.
00654       ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS
00655       ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS
00656 
00657       // Cleanup the dynamically preallocated arrays.
00658       // (none)
00659 
00660       // Cleanup the dynamically preallocated objects.
00661       ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
00662 #if defined (ACE_HAS_THREADS)
00663       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00664                                       ACE_STATIC_OBJECT_LOCK)
00665 #endif /* ACE_HAS_THREADS */
00666 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00667       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
00668                                       ACE_MT_CORBA_HANDLER_LOCK)
00669       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
00670       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00671                                       ACE_SIG_HANDLER_LOCK)
00672       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex,
00673                                       ACE_SINGLETON_NULL_LOCK)
00674       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex,
00675                                       ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
00676       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
00677 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
00678       ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
00679                                       ACE_TOKEN_MANAGER_CREATION_LOCK)
00680       ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX,
00681                                       ACE_TOKEN_INVARIANTS_CREATION_LOCK)
00682 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
00683       ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex,
00684                                       ACE_PROACTOR_EVENT_LOOP_LOCK)
00685 # endif /* ACE_MT_SAFE */
00686 #endif /* ! ACE_HAS_STATIC_PREALLOCATION */
00687 
00688 #if defined (ACE_HAS_THREADS)
00689       ACE_Static_Object_Lock::cleanup_lock ();
00690 #endif /* ACE_HAS_THREADS */
00691     }
00692 
00693 #if !defined (ACE_LACKS_ACE_SVCCONF)
00694   delete ace_service_config_sig_handler_;
00695   ace_service_config_sig_handler_ = 0;
00696 #endif /* ! ACE_LACKS_ACE_SVCCONF */
00697 
00698 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00699   delete internal_lock_;
00700   internal_lock_ = 0;
00701 
00702   delete singleton_null_lock_;
00703   singleton_null_lock_ = 0;
00704 
00705   delete singleton_recursive_lock_;
00706   singleton_recursive_lock_ = 0;
00707 #endif /* ACE_MT_SAFE */
00708 
00709   // Indicate that this ACE_Object_Manager instance has been shut down.
00710   object_manager_state_ = OBJ_MAN_SHUT_DOWN;
00711 
00712   // Then, ensure that the ACE_OS_Object_Manager gets shut down.
00713   if (this == instance_ && ACE_OS_Object_Manager::instance_)
00714     ACE_OS_Object_Manager::instance_->fini ();
00715 
00716   if (dynamically_allocated_)
00717     {
00718       delete this;
00719     }
00720 
00721   if (this == instance_)
00722     instance_ = 0;
00723 
00724   return 0;
00725 }

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 176 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_OS_Object_Manager::instance(), instance_, ACE_Object_Manager_Base::next_, preallocations_, ACE_Service_Config::signal_handler(), ACE_Trace::start_tracing(), and ACE_Object_Manager_Base::starting_up_i().

Referenced by ACE_Object_Manager(), and ACE::init().

00177 {
00178   if (starting_up_i ())
00179     {
00180       // First, indicate that the ACE_Object_Manager instance is being
00181       // initialized.
00182       object_manager_state_ = OBJ_MAN_INITIALIZING;
00183 
00184       // Only The Instance sets up with ACE_OS_Object_Manager and initializes
00185       // the preallocated objects.
00186       if (this == instance_)
00187         {
00188           // Make sure that the ACE_OS_Object_Manager has been created,
00189           // and register with it for chained fini ().
00190           ACE_OS_Object_Manager::instance ()->next_ = this;
00191 
00192 #     if defined (ACE_HAS_BUILTIN_ATOMIC_OP)
00193           ACE_Atomic_Op<ACE_Thread_Mutex, long>::init_functions ();
00194           ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long>::init_functions ();
00195 #     endif /* ACE_HAS_BUILTIN_ATOMIC_OP */
00196 
00197 #     if !defined (ACE_LACKS_ACE_SVCCONF)
00198           // Construct the ACE_Service_Config's signal handler.
00199           ACE_NEW_RETURN (ace_service_config_sig_handler_,
00200                      ACE_Sig_Adapter (&ACE_Service_Config::handle_signal), -1);
00201           ACE_Service_Config::signal_handler (ace_service_config_sig_handler_);
00202 #     endif /* ! ACE_LACKS_ACE_SVCCONF */
00203 
00204           // Allocate the preallocated (hard-coded) object instances.
00205           ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK)
00206 #     if defined (ACE_HAS_THREADS)
00207           ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00208                                   ACE_STATIC_OBJECT_LOCK)
00209 #     endif /* ACE_HAS_THREADS */
00210 #     if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00211           ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
00212                                   ACE_MT_CORBA_HANDLER_LOCK)
00213           ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK)
00214           ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00215                                   ACE_SIG_HANDLER_LOCK)
00216           ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK)
00217           ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex,
00218                                   ACE_SINGLETON_RECURSIVE_THREAD_LOCK)
00219           ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK)
00220 #if !defined (ACE_LACKS_ACE_TOKEN) && defined (ACE_HAS_TOKENS_LIBRARY)
00221           ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
00222                                   ACE_TOKEN_MANAGER_CREATION_LOCK)
00223           ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX,
00224                                   ACE_TOKEN_INVARIANTS_CREATION_LOCK)
00225 #endif /* ! ACE_LACKS_ACE_TOKEN && ACE_HAS_TOKENS_LIBRARY */
00226           ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex,
00227                                   ACE_PROACTOR_EVENT_LOOP_LOCK)
00228 #     endif /* ACE_MT_SAFE */
00229         }
00230 
00231       if (this == instance_)
00232         {
00233           // Hooks for preallocated objects and arrays provided by application.
00234           ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS
00235           ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS
00236 
00237 #     if defined (ACE_HAS_TSS_EMULATION)
00238           // Initialize the main thread's TS storage.
00239           ACE_TSS_Emulation::tss_open (ts_storage_);
00240 #     endif /* ACE_HAS_TSS_EMULATION */
00241 
00242 #if defined (ACE_DISABLE_WIN32_ERROR_WINDOWS) && \
00243     defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00244 #if defined (_DEBUG) && (defined (_MSC_VER) || defined (__INTEL_COMPILER))
00245           // This will keep the ACE_Assert window
00246           _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
00247           _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR );
00248 #endif /* _DEBUG && _MSC_VER || __INTEL_COMPILER */
00249 
00250           // And this will catch all unhandled exceptions.
00251           SetUnhandledExceptionFilter (&ACE_UnhandledExceptionFilter);
00252 #endif /* ACE_DISABLE_WIN32_ERROR_WINDOWS && ACE_WIN32 && !ACE_HAS_WINCE */
00253 
00254 
00255 #     if !defined (ACE_LACKS_ACE_SVCCONF)
00256           ACE_NEW_RETURN (preallocations_,
00257                           ACE_Object_Manager_Preallocations,
00258                           -1);
00259 #     endif /* ! ACE_LACKS_ACE_SVCCONF */
00260 
00261           // Open the main thread's ACE_Log_Msg.
00262           if (0 == ACE_LOG_MSG)
00263             return -1;
00264         }
00265 
00266       // Finally, indicate that the ACE_Object_Manager instance has
00267       // been initialized.
00268       object_manager_state_ = OBJ_MAN_INITIALIZED;
00269 
00270 #if defined (ACE_HAS_TRACE)
00271       // Allow tracing again (useful if user does init/fini/init)
00272       ACE_Trace::start_tracing ();
00273 #endif /* ACE_HAS_TRACE */
00274 
00275       return 0;
00276     } else {
00277       // Had already initialized.
00278       return 1;
00279     }
00280 }

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 322 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::fini(), and ACE::init().

00323 {
00324   // This function should be called during construction of static
00325   // instances, or before any other threads have been created in
00326   // the process.  So, it's not thread safe.
00327 
00328   if (instance_ == 0)
00329     {
00330       ACE_Object_Manager *instance_pointer = 0;
00331 
00332       ACE_NEW_RETURN (instance_pointer,
00333                       ACE_Object_Manager,
00334                       0);
00335       ACE_ASSERT (instance_pointer == instance_);
00336 
00337       instance_pointer->dynamically_allocated_ = true;
00338 
00339       return instance_pointer;
00340     }
00341   else
00342     return instance_;
00343 }

ACE_Object_Manager& ACE_Object_Manager::operator= const ACE_Object_Manager  )  [private]
 

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 150 of file Object_Manager.cpp.

References instance_, and ACE_Object_Manager_Base::shutting_down_i().

Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance(), ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance(), ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Service_Repository::instance(), ACE_Framework_Repository::instance(), and ACE_Thread_Manager::wait().

00151 {
00152   return ACE_Object_Manager::instance_  ?  instance_->shutting_down_i ()  :  1;
00153 }

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 144 of file Object_Manager.cpp.

References instance_, and ACE_Object_Manager_Base::starting_up_i().

Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance(), ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance(), ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Singleton< TYPE, ACE_LOCK >::instance(), ACE_Service_Repository::instance(), and ACE_Framework_Repository::instance().

00145 {
00146   return ACE_Object_Manager::instance_  ?  instance_->starting_up_i ()  :  1;
00147 }


Friends And Related Function Documentation

friend class ACE_Object_Manager_Manager [friend]
 

Definition at line 430 of file Object_Manager.h.


Member Data Documentation

ACE_Sig_Adapter* ACE_Object_Manager::ace_service_config_sig_handler_ [private]
 

ACE_Service_Config signal handler.

Definition at line 336 of file Object_Manager.h.

Referenced by fini(), and init().

ACE_OS_Exit_Info ACE_Object_Manager::exit_info_ [private]
 

For at_exit support.

Definition at line 329 of file Object_Manager.h.

Referenced by at_exit_i(), and fini().

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Object_Manager * ACE_Object_Manager::instance_ = 0 [static, private]
 

Singleton pointer.

Definition at line 55 of file Object_Manager.cpp.

Referenced by ACE_Object_Manager(), at_exit_i(), fini(), init(), instance(), shutting_down(), and starting_up().

void * ACE_Object_Manager::preallocated_array = { 0 } [static]
 

Table of preallocated arrays.

Definition at line 61 of file Object_Manager.cpp.

void * ACE_Object_Manager::preallocated_object = { 0 } [static]
 

Table of preallocated objects.

Definition at line 58 of file Object_Manager.cpp.

ACE_Object_Manager_Preallocations* ACE_Object_Manager::preallocations_ [private]
 

Preallocated objects collection.

Definition at line 333 of file Object_Manager.h.

Referenced by fini(), and init().


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 12:56:10 2008 for ACE by doxygen 1.3.6