diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-08-31 17:25:02 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-08-31 17:25:02 +0000 |
commit | 624070417cb6e7640174cbc2c0966ba9a2469353 (patch) | |
tree | 600e943508fbac05c0e304f2d8c0096b7eef5e9a /ace/Object_Manager.cpp | |
parent | 573f3e3eac8417e2d41503beb9c7167e9f67bae1 (diff) | |
download | ATCD-624070417cb6e7640174cbc2c0966ba9a2469353.tar.gz |
reorganized to provide the ACE_Object_Manager_Base class
Diffstat (limited to 'ace/Object_Manager.cpp')
-rw-r--r-- | ace/Object_Manager.cpp | 670 |
1 files changed, 394 insertions, 276 deletions
diff --git a/ace/Object_Manager.cpp b/ace/Object_Manager.cpp index 84a9dd589f3..37ab6203861 100644 --- a/ace/Object_Manager.cpp +++ b/ace/Object_Manager.cpp @@ -5,7 +5,7 @@ #include "ace/Object_Manager.h" #include "ace/Token_Manager.h" #if !defined (ACE_HAS_WINCE) -#include "ace/Naming_Context.h" +# include "ace/Naming_Context.h" #endif /* !ACE_HAS_WINCE */ #include "ace/Service_Manager.h" #include "ace/Service_Config.h" @@ -18,7 +18,7 @@ #include "ace/Signal.h" #if !defined (__ACE_INLINE__) -#include "ace/Object_Manager.i" +# include "ace/Object_Manager.i" #endif /* __ACE_INLINE__ */ ACE_RCSID(ace, Object_Manager, "$Id$") @@ -43,12 +43,11 @@ ACE_RCSID(ace, Object_Manager, "$Id$") ACE_Object_Manager *ACE_Object_Manager::instance_ = 0; int ACE_Object_Manager::starting_up_ = 1; -int ACE_Object_Manager::shutting_down_ = 0; -ACE_Sig_Set *ACE_Object_Manager::default_mask_p_ = 0; -void *ACE_Object_Manager::managed_object[ACE_MAX_MANAGED_OBJECTS] = { 0 }; +int ACE_Object_Manager::shutting_down_ = 0; -u_int ACE_Object_Manager::next_managed_object = 0; +u_int ACE_Object_Manager::initialized_ = 0; +// Flag to allow handling of multiple calls to init (). void *ACE_Object_Manager::preallocated_object[ ACE_Object_Manager::ACE_PREALLOCATED_OBJECTS] = { 0 }; @@ -56,8 +55,6 @@ void *ACE_Object_Manager::preallocated_object[ void *ACE_Object_Manager::preallocated_array[ ACE_Object_Manager::ACE_PREALLOCATED_ARRAYS] = { 0 }; -ACE_Sig_Adapter *ace_service_config_sig_handler = 0; - // Handy macros for use by ACE_Object_Manager constructor to // preallocate or delete an object or array, either statically (in // global data) or dynamically (on the heap). @@ -76,13 +73,13 @@ ACE_Sig_Adapter *ace_service_config_sig_handler = 0; # define ACE_PREALLOCATE_OBJECT(TYPE, ID)\ {\ ACE_Cleanup_Adapter<TYPE> *obj_p;\ - ACE_NEW (obj_p, ACE_Cleanup_Adapter<TYPE>);\ + ACE_NEW_RETURN (obj_p, ACE_Cleanup_Adapter<TYPE>, -1);\ preallocated_object[ID] = obj_p;\ } # define ACE_PREALLOCATE_ARRAY(TYPE, ID, COUNT)\ {\ ACE_Cleanup_Adapter<TYPE[COUNT]> *array_p;\ - ACE_NEW (array_p, ACE_Cleanup_Adapter<TYPE[COUNT]>);\ + ACE_NEW_RETURN (array_p, ACE_Cleanup_Adapter<TYPE[COUNT]>, -1);\ preallocated_array[ID] = array_p;\ } # define ACE_DELETE_PREALLOCATED_OBJECT(TYPE, ID)\ @@ -110,13 +107,12 @@ private: ACE_Static_Svc_Descriptor ace_svc_desc_ACE_Service_Manager; }; -static -ACE_Object_Manager_Preallocations *ace_object_manager_preallocations = 0; - // We can't use the ACE_SVC_FACTORY_DECLARE macro here because this // needs to be in the ACE_Export context rather than the // ACE_Svc_Export context. -extern "C" ACE_Export ACE_Service_Object *_make_ACE_Service_Manager (ACE_Service_Object_Exterminator *); +extern "C" ACE_Export +ACE_Service_Object * +_make_ACE_Service_Manager (ACE_Service_Object_Exterminator *); ACE_Object_Manager_Preallocations::ACE_Object_Manager_Preallocations (void) { @@ -164,103 +160,287 @@ ACE_Object_Manager_Preallocations::~ACE_Object_Manager_Preallocations (void) { } -ACE_Object_Manager::ACE_Object_Manager (void) - // , lock_ is initialized in the function body. - // - // With ACE_HAS_TSS_EMULATION, ts_storage_ is initialized by the call to - // ACE_OS::tss_open () in the function body. +ACE_Object_Manager_Base::ACE_Object_Manager_Base (void) + : registered_objects_ (0) +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) + , internal_lock_ (new ACE_Recursive_Thread_Mutex) + , singleton_null_lock_ (0) + , singleton_thread_locks_ (0) + , singleton_mutex_locks_ (0) + , singleton_recursive_lock_ (0) + , singleton_rw_locks_ (0) +# endif /* ACE_MT_SAFE */ { - ACE_MT (ACE_NEW (lock_, ACE_Recursive_Thread_Mutex)); + // ::fprintf (stderr, "ACE_Object_Manager_Base, this: %p\n", this); // ???? +} -#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) - // Store the address of this static instance so that instance () - // doesn't allocate a new one when called. - instance_ = this; -#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ +int +ACE_Object_Manager::init (void) +{ + if (initialized_ == 0) + { + initialized_ = 1; + + if (instance_ == 0) + { + // Allocate the ACE_Object_Manager instance on the heap. Assume + // that the application will call fini () to destroy it. + ACE_Object_Manager::instance (); + } + + // Allocate the preallocated (hard-coded) object instances. + ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) +# if defined (ACE_HAS_THREADS) + ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_STATIC_OBJECT_LOCK) +# endif /* ACE_HAS_THREADS */ +# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) + ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_LOG_MSG_INSTANCE_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_MT_CORBA_HANDLER_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_OS_MONITOR_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_SIG_HANDLER_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_SINGLETON_RECURSIVE_THREAD_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, + ACE_TOKEN_MANAGER_CREATION_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, + ACE_TOKEN_INVARIANTS_CREATION_LOCK) + ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_TSS_CLEANUP_LOCK) +# if defined (ACE_HAS_TSS_EMULATION) && defined(ACE_USE_NATIVE_KEYS) + ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_TSS_BASE_LOCK) +# endif /* ACE_HAS_TSS_EMULATION && ACE_USE_NATIVE_KEYS */ +# endif /* ACE_MT_SAFE */ + + // Do this after the allocation of ACE_STATIC_OBJECT_LOCK. It + // shouldn't matter, but just in case + // ACE_Static_Object_Lock::instance () gets changed . . . + ACE_NEW_RETURN (instance_->registered_objects_, + ACE_Unbounded_Queue<ACE_Cleanup_Info>, -1); + // ::fprintf (stderr, "init: allocated registered_objects_ for" + // " %p\n", instance_); // ???? + + // Hooks for preallocated objects and arrays provided by application. + ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS + ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS + +# if defined (ACE_HAS_TSS_EMULATION) + // Initialize the main thread's TS storage. + ACE_TSS_Emulation::tss_open (instance_->ts_storage_); +# endif /* ACE_HAS_TSS_EMULATION */ + + // Open Winsock (no-op on other platforms). + ACE_OS::socket_init (ACE_WSOCK_VERSION); + + ACE_NEW_RETURN (instance_->preallocations_, + ACE_Object_Manager_Preallocations, -1); + + // Open the main thread's ACE_Log_Msg. + (void) ACE_LOG_MSG; + + ACE_NEW_RETURN (instance_->default_mask_, + ACE_Sig_Set (1), -1); + + // Finally, indicate that the ACE_Object_Manager instance has + // been constructed. + instance_->starting_up_ = 0; + + return 0; + } else { + // Had already initialized. + return -1; + } +} + +int +ACE_Object_Manager::fini (void) +{ + if (instance_ == 0) + // Too late. Or, maybe too early. Either fini () has already + // been called, or init () was never called. + return -1; + + // No mutex here. Only the main thread should destroy the singleton + // ACE_Object_Manager instance. - // Allocate the preallocated (hard-coded) object instances. - ACE_PREALLOCATE_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) + // First, indicate that the ACE_Object_Manager instance is (being) + // destroyed. If an object tries to register after this, it will be + // refused. + instance_->shutting_down_ = 1; + + ACE_Trace::stop_tracing (); + + ACE_Cleanup_Info info; + + // Close and possibly delete all service instances in the Service + // Repository. + ACE_Service_Config::fini_svcs (); + + // Call all registered cleanup hooks, in reverse order of + // registration. + while (instance_->registered_objects_ && + instance_->registered_objects_->dequeue_head (info) != -1) + { + if (info.cleanup_hook_ == (ACE_CLEANUP_FUNC) ace_cleanup_destroyer) + // The object is an ACE_Cleanup. + ace_cleanup_destroyer ((ACE_Cleanup *) info.object_, info.param_); + else + (*info.cleanup_hook_) (info.object_, info.param_); + } + + // Close the main thread's TSS, including its Log_Msg instance. + ACE_OS::cleanup_tss (1 /* main thread */); + + // + // Note: Do not access Log Msg after this since it is gone + // + + // Unlink all services in the Service Repository and close/delete + // all ACE library services and singletons. + ACE_Service_Config::close (); + + // Close down Winsock (no-op on other platforms). + ACE_OS::socket_fini (); + + delete instance_->preallocations_; + instance_->preallocations_ = 0; + + // Close the ACE_Allocator. + ACE_Allocator::close_singleton (); + +#if ! defined (ACE_HAS_STATIC_PREALLOCATION) + // Hooks for deletion of preallocated objects and arrays provided by + // application. + ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS + ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS + + // Cleanup the dynamically preallocated arrays. + // (none) + + // Cleanup the dynamically preallocated objects. + ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) #if defined (ACE_HAS_THREADS) - ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, ACE_STATIC_OBJECT_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_STATIC_OBJECT_LOCK) #endif /* ACE_HAS_THREADS */ # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) - ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_LOG_MSG_INSTANCE_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_MT_CORBA_HANDLER_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_OS_MONITOR_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, ACE_SIG_HANDLER_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_SINGLETON_RECURSIVE_THREAD_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, - ACE_TOKEN_MANAGER_CREATION_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_TOKEN_CONST::MUTEX, - ACE_TOKEN_INVARIANTS_CREATION_LOCK) - ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, ACE_TSS_CLEANUP_LOCK) -# if defined (ACE_HAS_TSS_EMULATION) && defined(ACE_USE_NATIVE_KEYS) - ACE_PREALLOCATE_OBJECT (ACE_Recursive_Thread_Mutex, ACE_TSS_BASE_LOCK) -# endif /* ACE_HAS_TSS_EMULATION && ACE_USE_NATIVE_KEYS */ + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, + ACE_LOG_MSG_INSTANCE_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, + ACE_MT_CORBA_HANDLER_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_OS_MONITOR_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_SIG_HANDLER_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_SINGLETON_RECURSIVE_THREAD_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, + ACE_TOKEN_MANAGER_CREATION_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, + ACE_TOKEN_INVARIANTS_CREATION_LOCK) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_TSS_CLEANUP_LOCK) +# if defined (ACE_HAS_TSS_EMULATION) && defined(ACE_USE_NATIVE_KEYS) + ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, + ACE_TSS_BASE_LOCK) +# endif /* ACE_HAS_TSS_EMULATION && ACE_USE_NATIVE_KEYS */ # endif /* ACE_MT_SAFE */ +#endif /* ! ACE_HAS_STATIC_PREALLOCATION */ - // Do this after the allocation of ACE_STATIC_OBJECT_LOCK. It shouldn't - // matter, but just in case ACE_Static_Object_Lock::instance () gets - // changed . . . - ACE_NEW (registered_objects_, ACE_Unbounded_Queue<ACE_Cleanup_Info>); - - // Hooks for preallocated objects and arrays provided by application. - ACE_APPLICATION_PREALLOCATED_OBJECT_DEFINITIONS - ACE_APPLICATION_PREALLOCATED_ARRAY_DEFINITIONS - - // Construct the ACE_Service_Config's signal handler. - ACE_NEW (ace_service_config_sig_handler, - ACE_Sig_Adapter (&ACE_Service_Config::handle_signal)); - ACE_Service_Config::signal_handler (ace_service_config_sig_handler); +#if defined (ACE_HAS_THREADS) + ACE_Static_Object_Lock::cleanup_lock (); +#endif /* ACE_HAS_THREADS */ -#if defined (ACE_HAS_TSS_EMULATION) - // Initialize the main thread's TS storage. - ACE_TSS_Emulation::tss_open (ts_storage_); -#endif /* ACE_HAS_TSS_EMULATION */ + delete instance_->default_mask_; + instance_->default_mask_ = 0; - // Open Winsock (no-op on other platforms). - ACE_OS::socket_init (ACE_WSOCK_VERSION); +#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) + if (instance_->dynamically_allocated_) + { + delete instance_; + instance_ = 0; + } +#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ - ACE_NEW (ace_object_manager_preallocations, - ACE_Object_Manager_Preallocations); + return 0; +} - // Open the main thread's ACE_Log_Msg. - (void) ACE_LOG_MSG; +ACE_Object_Manager::ACE_Object_Manager (void) + // With ACE_HAS_TSS_EMULATION, ts_storage_ is initialized by the call to + // ACE_OS::tss_open () in the function body. + : dynamically_allocated_ (0) + , preallocations_ (0) + , default_mask_ (0) + , ace_service_config_sig_handler_ (0) +{ + if (instance_ == 0) + { + // Store the address of the instance so that instance () doesn't + // allocate a new one when called. + instance_ = this; - // Finally, indicate that the ACE_Object_Manager instance has been - // constructed. - ACE_Object_Manager::starting_up_ = 0; + // Construct the ACE_Service_Config's signal handler. + ACE_NEW (ace_service_config_sig_handler_, + ACE_Sig_Adapter (&ACE_Service_Config::handle_signal)); + ACE_Service_Config::signal_handler (ace_service_config_sig_handler_); - ACE_NEW (ACE_Object_Manager::default_mask_p_, - ACE_Sig_Set (1)); + init (); + } + // else if instance_ was not 0, then then another + // ACE_Object_Manager has already been instantiated. + // Don't do anything, so that it will own all + // ACE_Object_Manager resources. } ACE_Object_Manager * ACE_Object_Manager::instance (void) { - // This function should be call during construction of static - // instances, so it's not thread safe. + // This function should be called during construction of static + // instances, or before any other threads have been created in + // the process. So, it's not thread safe. if (instance_ == 0) - ACE_NEW_RETURN (instance_, ACE_Object_Manager, 0); + { + ACE_Object_Manager *instance_pointer; + + ACE_NEW_RETURN (instance_pointer, ACE_Object_Manager, 0); + ACE_ASSERT (instance_pointer == instance_); + +#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) + instance_pointer->dynamically_allocated_ = 1; +#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ - return instance_; + return instance_pointer; + } + else + { + return instance_; + } } int ACE_Object_Manager::starting_up () { - return ACE_Object_Manager::starting_up_; + return starting_up_; } int ACE_Object_Manager::shutting_down () { - return ACE_Object_Manager::shutting_down_; + return shutting_down_; +} + +ACE_Sig_Set & +ACE_Object_Manager::default_mask (void) +{ + return *ACE_Object_Manager::instance ()->default_mask_; } int @@ -268,7 +448,12 @@ ACE_Object_Manager::at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) { - ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, *lock_, -1)); + ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, + *instance_->internal_lock_, -1)); + + // ::fprintf (stderr, "at_exit_i, this: %p, registered_objects_ is %p\n", + // this, + // registered_objects_); // ???? if (shutting_down ()) { @@ -278,7 +463,8 @@ ACE_Object_Manager::at_exit_i (void *object, // Check for already in queue, and return 1 if so. ACE_Cleanup_Info *info = 0; - for (ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info> iter (*registered_objects_); + for (ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info> + iter (*registered_objects_); iter.next (info) != 0; iter.advance ()) { @@ -302,27 +488,10 @@ ACE_Object_Manager::at_exit_i (void *object, #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) -// These are global so that they don't have to be declared in the -// header file. That would cause nasty circular include problems. -static ACE_Cleanup_Adapter<ACE_Null_Mutex> * -ACE_Object_Manager_singleton_null_lock = 0; - -static ACE_Array<ACE_Thread_Mutex *> * -ACE_Object_Manager_singleton_thread_locks = 0; - -static ACE_Array<ACE_Mutex *> * -ACE_Object_Manager_singleton_mutex_locks = 0; - -static ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex> * -ACE_Object_Manager_singleton_recursive_lock = 0; - -static ACE_Array<ACE_RW_Thread_Mutex *> * -ACE_Object_Manager_singleton_rw_locks = 0; - int -ACE_Object_Manager::get_singleton_lock (ACE_Null_Mutex *&lock) +ACE_Object_Manager_Base::get_singleton_lock (ACE_Null_Mutex *&lock) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The preallocated lock has not been constructed yet. @@ -331,9 +500,10 @@ ACE_Object_Manager::get_singleton_lock (ACE_Null_Mutex *&lock) // preallocated lock is not available. Allocate a lock to use, // for interface compatibility, though there should be no // contention on it. - if (ACE_Object_Manager_singleton_null_lock == 0) + if (ACE_Object_Manager::instance ()->singleton_null_lock_ == 0) { - ACE_NEW_RETURN (ACE_Object_Manager_singleton_null_lock, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_null_lock_, ACE_Cleanup_Adapter<ACE_Null_Mutex>, -1); @@ -342,8 +512,9 @@ ACE_Object_Manager::get_singleton_lock (ACE_Null_Mutex *&lock) // destructor, so it will clean it up as a special case. } - if (ACE_Object_Manager_singleton_null_lock != 0) - lock = &ACE_Object_Manager_singleton_null_lock->object (); + if (ACE_Object_Manager::instance ()->singleton_null_lock_ != 0) + lock = &ACE_Object_Manager::instance ()->singleton_null_lock_-> + object (); } else // Use the Object_Manager's preallocated lock. @@ -354,11 +525,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_Null_Mutex *&lock) } int -ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) +ACE_Object_Manager_Base::get_singleton_lock (ACE_Thread_Mutex *&lock) { if (lock == 0) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The Object_Manager and its internal lock have not been @@ -372,15 +543,17 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) // Add the new lock to the array of locks to be deleted // at program termination. - if (ACE_Object_Manager_singleton_thread_locks == 0) + if (ACE_Object_Manager::instance ()->singleton_thread_locks_ == 0) { // Create the array, then insert the new lock. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_thread_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_thread_locks_, ACE_Array<ACE_Thread_Mutex *> ( (size_t) 1, (ACE_Thread_Mutex *) 0), -1); - (*ACE_Object_Manager_singleton_thread_locks)[0] = lock; + (*ACE_Object_Manager::instance ()->singleton_thread_locks_)[0] = + lock; } else { @@ -388,10 +561,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) // Copy the array pointer. ACE_Array<ACE_Thread_Mutex *> *tmp = - ACE_Object_Manager_singleton_thread_locks; + ACE_Object_Manager::instance ()->singleton_thread_locks_; // Create a new array with one more slot than the current one. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_thread_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_thread_locks_, ACE_Array<ACE_Thread_Mutex *> ( tmp->size () + (size_t) 1, (ACE_Thread_Mutex *) 0), @@ -399,11 +573,12 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) // Copy the old array to the new array. for (u_int i = 0; i < tmp->size (); ++i) - (*ACE_Object_Manager_singleton_thread_locks)[i] = (*tmp) [i]; + (*ACE_Object_Manager::instance ()-> + singleton_thread_locks_)[i] = (*tmp) [i]; // Insert the new lock at the end of the array. - (*ACE_Object_Manager_singleton_thread_locks)[tmp->size ()] = - lock; + (*ACE_Object_Manager::instance ()->singleton_thread_locks_) + [tmp->size ()] = lock; delete tmp; } @@ -414,7 +589,8 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) // ensure that only one thread allocates it. ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, - *ACE_Object_Manager::instance ()->lock_, + *ACE_Object_Manager::instance ()-> + internal_lock_, -1)); if (lock == 0) @@ -425,8 +601,9 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) -1); lock = &lock_adapter->object (); - // Register the lock for destruction at program termination. - // This call will cause us to grab the ACE_Object_Manager lock_ + // Register the lock for destruction at program + // termination. This call will cause us to grab the + // ACE_Object_Manager::instance ()->internal_lock_ // again; that's why it is a recursive lock. ACE_Object_Manager::at_exit (lock_adapter); } @@ -437,11 +614,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_Thread_Mutex *&lock) } int -ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) +ACE_Object_Manager_Base::get_singleton_lock (ACE_Mutex *&lock) { if (lock == 0) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The Object_Manager and its internal lock have not been @@ -455,15 +632,17 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) // Add the new lock to the array of locks to be deleted // at program termination. - if (ACE_Object_Manager_singleton_mutex_locks == 0) + if (ACE_Object_Manager::instance ()->singleton_mutex_locks_ == 0) { // Create the array, then insert the new lock. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_mutex_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_mutex_locks_, ACE_Array<ACE_Mutex *> ( (size_t) 1, (ACE_Mutex *) 0), -1); - (*ACE_Object_Manager_singleton_mutex_locks)[0] = lock; + (*ACE_Object_Manager::instance ()->singleton_mutex_locks_)[0] = + lock; } else { @@ -471,10 +650,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) // Copy the array pointer. ACE_Array<ACE_Mutex *> *tmp = - ACE_Object_Manager_singleton_mutex_locks; + ACE_Object_Manager::instance ()->singleton_mutex_locks_; // Create a new array with one more slot than the current one. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_mutex_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_mutex_locks_, ACE_Array<ACE_Mutex *> ( tmp->size () + (size_t) 1, (ACE_Mutex *) 0), @@ -482,11 +662,12 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) // Copy the old array to the new array. for (u_int i = 0; i < tmp->size (); ++i) - (*ACE_Object_Manager_singleton_mutex_locks)[i] = (*tmp) [i]; + (*ACE_Object_Manager::instance ()->singleton_mutex_locks_)[i] = + (*tmp) [i]; // Insert the new lock at the end of the array. - (*ACE_Object_Manager_singleton_mutex_locks)[tmp->size ()] = - lock; + (*ACE_Object_Manager::instance ()->singleton_mutex_locks_) + [tmp->size ()] = lock; delete tmp; } @@ -497,7 +678,8 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) // ensure that only one thread allocates it. ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, - *ACE_Object_Manager::instance ()->lock_, + *ACE_Object_Manager::instance ()-> + internal_lock_, -1)); if (lock == 0) @@ -508,8 +690,9 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) -1); lock = &lock_adapter->object (); - // Register the lock for destruction at program termination. - // This call will cause us to grab the ACE_Object_Manager lock_ + // Register the lock for destruction at program + // termination. This call will cause us to grab the + // ACE_Object_Manager::instance ()->internal_lock_ // again; that's why it is a recursive lock. ACE_Object_Manager::at_exit (lock_adapter); } @@ -520,9 +703,9 @@ ACE_Object_Manager::get_singleton_lock (ACE_Mutex *&lock) } int -ACE_Object_Manager::get_singleton_lock (ACE_Recursive_Thread_Mutex *&lock) +ACE_Object_Manager_Base::get_singleton_lock (ACE_Recursive_Thread_Mutex *&lock) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The preallocated lock has not been constructed yet. @@ -531,17 +714,19 @@ ACE_Object_Manager::get_singleton_lock (ACE_Recursive_Thread_Mutex *&lock) // preallocated lock is not available. Allocate a lock to use, // for interface compatibility, though there should be no // contention on it. - if (ACE_Object_Manager_singleton_recursive_lock == 0) - ACE_NEW_RETURN (ACE_Object_Manager_singleton_recursive_lock, + if (ACE_Object_Manager::instance ()->singleton_recursive_lock_ == 0) + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_recursive_lock_, ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex>, -1); - // Can't register with the ACE_Object_Manager here! The - // lock's declaration is visible to the ACE_Object_Manager - // destructor, so it will clean it up as a special case. + // Can't register with the ACE_Object_Manager here! The lock's + // declaration is visible to the ACE_Object_Manager destructor, + // so it will clean it up as a special case. - if (ACE_Object_Manager_singleton_recursive_lock != 0) - lock = &ACE_Object_Manager_singleton_recursive_lock->object (); + if (ACE_Object_Manager::instance ()->singleton_recursive_lock_ != 0) + lock = &ACE_Object_Manager::instance ()->singleton_recursive_lock_-> + object (); } else // Use the Object_Manager's preallocated lock. @@ -553,11 +738,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_Recursive_Thread_Mutex *&lock) } int -ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) +ACE_Object_Manager_Base::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) { if (lock == 0) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The Object_Manager and its internal lock have not been @@ -571,15 +756,17 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) // Add the new lock to the array of locks to be deleted // at program termination. - if (ACE_Object_Manager_singleton_rw_locks == 0) + if (ACE_Object_Manager::instance ()->singleton_rw_locks_ == 0) { // Create the array, then insert the new lock. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_rw_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_rw_locks_, ACE_Array<ACE_RW_Thread_Mutex *> ( (size_t) 1, (ACE_RW_Thread_Mutex *) 0), -1); - (*ACE_Object_Manager_singleton_rw_locks)[0] = lock; + (*ACE_Object_Manager::instance ()->singleton_rw_locks_)[0] = + lock; } else { @@ -587,10 +774,11 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) // Copy the array pointer. ACE_Array<ACE_RW_Thread_Mutex *> *tmp = - ACE_Object_Manager_singleton_rw_locks; + ACE_Object_Manager::instance ()->singleton_rw_locks_; // Create a new array with one more slot than the current one. - ACE_NEW_RETURN (ACE_Object_Manager_singleton_rw_locks, + ACE_NEW_RETURN (ACE_Object_Manager::instance ()-> + singleton_rw_locks_, ACE_Array<ACE_RW_Thread_Mutex *> ( tmp->size () + (size_t) 1, (ACE_RW_Thread_Mutex *) 0), @@ -598,10 +786,12 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) // Copy the old array to the new array. for (u_int i = 0; i < tmp->size (); ++i) - (*ACE_Object_Manager_singleton_rw_locks)[i] = (*tmp) [i]; + (*ACE_Object_Manager::instance ()->singleton_rw_locks_)[i] = + (*tmp) [i]; // Insert the new lock at the end of the array. - (*ACE_Object_Manager_singleton_rw_locks)[tmp->size ()] = lock; + (*ACE_Object_Manager::instance ()->singleton_rw_locks_) + [tmp->size ()] = lock; delete tmp; } @@ -612,7 +802,8 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) // ensure that only one thread allocates it. ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, - *ACE_Object_Manager::instance ()->lock_, + *ACE_Object_Manager::instance ()-> + internal_lock_, -1)); if (lock == 0) @@ -623,8 +814,10 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) -1); lock = &lock_adapter->object (); - // Register the lock for destruction at program termination. - // This call will cause us to grab the ACE_Object_Manager lock_ + + // Register the lock for destruction at program + // termination. This call will cause us to grab the + // ACE_Object_Manager::instance ()->internal_lock_ // again; that's why it is a recursive lock. ACE_Object_Manager::at_exit (lock_adapter); } @@ -635,126 +828,50 @@ ACE_Object_Manager::get_singleton_lock (ACE_RW_Thread_Mutex *&lock) } #endif /* ACE_MT_SAFE */ -ACE_Object_Manager::~ACE_Object_Manager (void) +// NOTE: this function needs to appear _after_ the +// get_singleton_lock () functions in order to compile with +// g++ 2.7.2.3. +ACE_Object_Manager_Base::~ACE_Object_Manager_Base (void) { - // No mutex here. Only the main thread should destroy the singleton - // ACE_Object_Manager instance. - - // First, indicate that the ACE_Object_Manager instance is (being) - // destroyed. If an object tries to register after this, it will be - // refused. - ACE_Object_Manager::shutting_down_ = 1; - - ACE_Trace::stop_tracing (); - - ACE_Cleanup_Info info; - - // Close and possibly delete all service instances in the Service - // Repository. - ACE_Service_Config::fini_svcs (); - - // Call all registered cleanup hooks, in reverse order of - // registration. - while (registered_objects_ && - registered_objects_->dequeue_head (info) != -1) - { - if (info.cleanup_hook_ == (ACE_CLEANUP_FUNC) ace_cleanup_destroyer) - // The object is an ACE_Cleanup. - ace_cleanup_destroyer ((ACE_Cleanup *) info.object_, info.param_); - else - (*info.cleanup_hook_) (info.object_, info.param_); - } - - // Close the main thread's TSS, including its Log_Msg instance. - ACE_OS::cleanup_tss (1 /* main thread */); - - // - // Note: Do not access Log Msg after this since it is gone - // - - // Unlink all services in the Service Repository and close/delete - // all ACE library services and singletons. - ACE_Service_Config::close (); +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) + delete singleton_null_lock_; + singleton_null_lock_ = 0; - // Close down Winsock (no-op on other platforms). - ACE_OS::socket_fini (); + delete singleton_thread_locks_; + singleton_thread_locks_ = 0; - delete ace_object_manager_preallocations; - ace_object_manager_preallocations = 0; + delete singleton_mutex_locks_; + singleton_mutex_locks_ = 0; - delete ace_service_config_sig_handler; - ace_service_config_sig_handler = 0; + delete singleton_recursive_lock_; + singleton_recursive_lock_ = 0; - ACE_MT (delete lock_; lock_ = 0); + delete singleton_rw_locks_; + singleton_rw_locks_ = 0; +#endif /* ACE_MT_SAFE */ delete registered_objects_; registered_objects_ = 0; - // Close the ACE_Allocator. - ACE_Allocator::close_singleton (); - -#if ! defined (ACE_HAS_STATIC_PREALLOCATION) - // Hooks for deletion of preallocated objects and arrays provided by - // application. - ACE_APPLICATION_PREALLOCATED_ARRAY_DELETIONS - ACE_APPLICATION_PREALLOCATED_OBJECT_DELETIONS - - // Cleanup the dynamically preallocated arrays. - // (none) - - // Cleanup the dynamically preallocated objects. - ACE_DELETE_PREALLOCATED_OBJECT (ACE_SYNCH_RW_MUTEX, ACE_FILECACHE_LOCK) -#if defined (ACE_HAS_THREADS) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_STATIC_OBJECT_LOCK) -#endif /* ACE_HAS_THREADS */ -# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_LOG_MSG_INSTANCE_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_MT_CORBA_HANDLER_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_DUMP_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_OS_MONITOR_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_SIG_HANDLER_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Null_Mutex, ACE_SINGLETON_NULL_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_SINGLETON_RECURSIVE_THREAD_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Thread_Mutex, ACE_THREAD_EXIT_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, - ACE_TOKEN_MANAGER_CREATION_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_TOKEN_CONST::MUTEX, - ACE_TOKEN_INVARIANTS_CREATION_LOCK) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_TSS_CLEANUP_LOCK) -# if defined (ACE_HAS_TSS_EMULATION) && defined(ACE_USE_NATIVE_KEYS) - ACE_DELETE_PREALLOCATED_OBJECT (ACE_Recursive_Thread_Mutex, - ACE_TSS_BASE_LOCK) -# endif /* ACE_HAS_TSS_EMULATION && ACE_USE_NATIVE_KEYS */ -# endif /* ACE_MT_SAFE */ -#endif /* ! ACE_HAS_STATIC_PREALLOCATION */ - -#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) - delete ACE_Object_Manager_singleton_null_lock; - ACE_Object_Manager_singleton_null_lock = 0; - - delete ACE_Object_Manager_singleton_thread_locks; - ACE_Object_Manager_singleton_thread_locks = 0; - - delete ACE_Object_Manager_singleton_mutex_locks; - ACE_Object_Manager_singleton_mutex_locks = 0; - - delete ACE_Object_Manager_singleton_recursive_lock; - ACE_Object_Manager_singleton_recursive_lock = 0; - - delete ACE_Object_Manager_singleton_rw_locks; - ACE_Object_Manager_singleton_rw_locks = 0; -#endif /* ACE_MT_SAFE */ + delete internal_lock_; + internal_lock_ = 0; +} -#if defined (ACE_HAS_THREADS) - ACE_Static_Object_Lock::cleanup_lock (); -#endif /* ACE_HAS_THREADS */ +ACE_Object_Manager::~ACE_Object_Manager (void) +{ +#if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) + // Clear the flag so that fini () doesn't delete again. + dynamically_allocated_ = 0; +#endif /* ACE_HAS_NONSTATIC_OBJECT_MANAGER */ - delete default_mask_p_; - default_mask_p_ = 0; + if (fini () != -1) + { + delete ace_service_config_sig_handler_; + ace_service_config_sig_handler_ = 0; + } + // else fini () had already been called. It would be safe + // to delete the 0 pointers again, but this allows us to + // add other code to the block above. } #if !defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) @@ -814,7 +931,7 @@ ACE_Static_Object_Lock_lock = 0; ACE_Recursive_Thread_Mutex * ACE_Static_Object_Lock::instance (void) { - if (ACE_Object_Manager::starting_up () || + if (ACE_Object_Manager::starting_up () || ACE_Object_Manager::shutting_down ()) { // The preallocated ACE_STATIC_OBJECT_LOCK has not been @@ -828,16 +945,17 @@ ACE_Static_Object_Lock::instance (void) ACE_Cleanup_Adapter<ACE_Recursive_Thread_Mutex>, 0); - // Can't register with the ACE_Object_Manager here! The - // lock's declaration is visible to the ACE_Object_Manager - // destructor, so it will clean it up as a special case. + // Can't register with the ACE_Object_Manager here! The lock's + // declaration is visible to the ACE_Object_Manager destructor, + // so it will clean it up as a special case. return &ACE_Static_Object_Lock_lock->object (); } else // Return the preallocated ACE_STATIC_OBJECT_LOCK. - return ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object - (ACE_Object_Manager::ACE_STATIC_OBJECT_LOCK); + return + ACE_Managed_Object<ACE_Recursive_Thread_Mutex>::get_preallocated_object + (ACE_Object_Manager::ACE_STATIC_OBJECT_LOCK); } void @@ -862,11 +980,11 @@ ACE_Static_Object_Lock::cleanup_lock (void) template class ACE_Managed_Object<ACE_Recursive_Thread_Mutex>; template class ACE_Managed_Object<ACE_Thread_Mutex>; # endif /* ACE_MT_SAFE */ -template class ACE_Cleanup_Adapter<ACE_SYNCH_RW_MUTEX>; -template class ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>; -template class ACE_Unbounded_Queue<ACE_Cleanup_Info>; -template class ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info>; -template class ACE_Node<ACE_Cleanup_Info>; + template class ACE_Cleanup_Adapter<ACE_SYNCH_RW_MUTEX>; + template class ACE_Managed_Object<ACE_SYNCH_RW_MUTEX>; + template class ACE_Unbounded_Queue<ACE_Cleanup_Info>; + template class ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info>; + template class ACE_Node<ACE_Cleanup_Info>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) # pragma instantiate ACE_Array<ACE_Thread_Mutex *> @@ -881,9 +999,9 @@ template class ACE_Node<ACE_Cleanup_Info>; # pragma instantiate ACE_Managed_Object<ACE_Recursive_Thread_Mutex> # pragma instantiate ACE_Managed_Object<ACE_Thread_Mutex> # endif /* ACE_MT_SAFE */ -#pragma instantiate ACE_Cleanup_Adapter<ACE_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Managed_Object<ACE_SYNCH_RW_MUTEX> -#pragma instantiate ACE_Unbounded_Queue<ACE_Cleanup_Info> -#pragma instantiate ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info> -#pragma instantiate ACE_Node<ACE_Cleanup_Info> +# pragma instantiate ACE_Cleanup_Adapter<ACE_SYNCH_RW_MUTEX> +# pragma instantiate ACE_Managed_Object<ACE_SYNCH_RW_MUTEX> +# pragma instantiate ACE_Unbounded_Queue<ACE_Cleanup_Info> +# pragma instantiate ACE_Unbounded_Queue_Iterator<ACE_Cleanup_Info> +# pragma instantiate ACE_Node<ACE_Cleanup_Info> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ |