diff options
-rw-r--r-- | ace/Singleton.cpp | 109 | ||||
-rw-r--r-- | ace/Singleton.h | 34 | ||||
-rw-r--r-- | ace/Token_Invariants.cpp | 28 | ||||
-rw-r--r-- | ace/Token_Invariants.h | 7 | ||||
-rw-r--r-- | ace/Token_Manager.cpp | 28 | ||||
-rw-r--r-- | ace/Token_Manager.h | 7 |
6 files changed, 71 insertions, 142 deletions
diff --git a/ace/Singleton.cpp b/ace/Singleton.cpp index 66e9902e8a5..2ace0c42c0d 100644 --- a/ace/Singleton.cpp +++ b/ace/Singleton.cpp @@ -26,17 +26,17 @@ ACE_Singleton<TYPE, LOCK>::dump (void) #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } -template <class TYPE, class LOCK> TYPE *& +template <class TYPE, class LOCK> ACE_Singleton<TYPE, LOCK> *& ACE_Singleton<TYPE, LOCK>::instance_i (void) { #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Pointer to the Singleton instance. This works around a bug with // G++... - static TYPE *instance_ = 0; + static ACE_Singleton<TYPE, LOCK> *singleton_ = 0; - return instance_; + return singleton_; #else - return ACE_Singleton<TYPE, LOCK>::instance_; + return ACE_Singleton<TYPE, LOCK>::singleton_; #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } @@ -54,25 +54,12 @@ ACE_Singleton<TYPE, LOCK>::singleton_lock_i (void) #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } -#if defined (ACE_HAS_SIG_C_FUNC) -extern "C" void -ACE_Singleton_cleanup (void *object, void *) -{ - ACE_TRACE ("ACE_Singleton_cleanup"); - - // This won't call the object's destructor, but it will deallocate - // its storage. That's better than nothing. - // (This function is only used if ACE_HAS_SIG_C_FUNC, e.g., on MVS.) - delete object; -} -#endif /* ACE_HAS_SIG_C_FUNC */ - template <class TYPE, class LOCK> TYPE * ACE_Singleton<TYPE, LOCK>::instance (void) { ACE_TRACE ("ACE_Singleton<TYPE, LOCK>::instance"); - TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i (); + ACE_Singleton<TYPE, LOCK> *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i (); // Perform the Double-Check pattern... if (singleton == 0) @@ -81,18 +68,14 @@ ACE_Singleton<TYPE, LOCK>::instance (void) if (singleton == 0) { - ACE_NEW_RETURN (singleton, TYPE, 0); + ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, LOCK>), 0); // Register for destruction with ACE_Object_Manager. -#if defined (ACE_HAS_SIG_C_FUNC) - ACE_Object_Manager::at_exit (singleton, ACE_Singleton_cleanup, 0); -#else - ACE_Object_Manager::at_exit (singleton, cleanup, 0); -#endif /* ACE_HAS_SIG_C_FUNC */ + ACE_Object_Manager::at_exit (singleton); } } - return singleton; + return singleton->instance_; } template <class TYPE, class LOCK> TYPE * @@ -102,25 +85,29 @@ ACE_Singleton<TYPE, LOCK>::instance (TYPE *new_instance) ACE_GUARD_RETURN (LOCK, ace_mon, (ACE_Singleton<TYPE, LOCK>::singleton_lock_i ()), 0); - TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i (); - TYPE *old_instance = singleton; - singleton = new_instance; + ACE_Singleton<TYPE, LOCK> *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i (); + TYPE *old_instance = singleton->instance_; + singleton->instance_ = new_instance; return old_instance; } template <class TYPE, class LOCK> void -ACE_Singleton<TYPE, LOCK>::cleanup (void *object, void *) +ACE_Singleton<TYPE, LOCK>::cleanup (void *) { - ACE_TRACE ("ACE_Singleton::cleanup"); + if (this->instance_ != 0) + { + delete this->instance_; + this->instance_ = 0; - delete (TYPE *) object; + delete this; + } } #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Pointer to the Singleton instance. -template <class TYPE, class LOCK> TYPE * -ACE_Singleton<TYPE, LOCK>::instance_ = 0; +template <class TYPE, class LOCK> ACE_Singleton<TYPE, LOCK> * +ACE_Singleton<TYPE, LOCK>::singleton_ = 0; // Lock the creation of the singleton. template <class TYPE, class LOCK> LOCK @@ -133,7 +120,7 @@ ACE_TSS_Singleton<TYPE, LOCK>::dump (void) ACE_TRACE ("ACE_TSS_Singleton<TYPE, LOCK>::dump"); #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - ACE_DEBUG ((LM_DEBUG, "instance_ = %x", instance_)); + ACE_DEBUG ((LM_DEBUG, "instance_ = %x", singleton_->instance_)); ace_singleton_lock_.dump(); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ @@ -147,81 +134,69 @@ ACE_TSS_Singleton<TYPE, LOCK>::instance (void) #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Pointer to the Singleton instance. This works around a bug with // G++... - static ACE_TSS<TYPE> *instance_ = 0; + static ACE_TSS_Singleton<TYPE, LOCK> *singleton_ = 0; // Lock the creation of the singleton. This works around a // "feature" of G++... ;-) static LOCK ace_singleton_lock_; // Perform the Double-Check pattern... - if (instance_ == 0) + if (singleton_ == 0) { ACE_GUARD_RETURN (LOCK, ace_mon, ace_singleton_lock_, 0); - if (instance_ == 0) + if (singleton_ == 0) { - ACE_NEW_RETURN (instance_, ACE_TSS<TYPE>, 0); + ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, LOCK>), 0); #if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */ // Register for destruction with ACE_Object_Manager. -#if defined (ACE_HAS_SIG_C_FUNC) - ACE_Object_Manager::at_thread_exit (instance_, - ACE_Singleton_cleanup, - 0); -#else - ACE_Object_Manager::at_thread_exit (instance_, cleanup, 0); -#endif /* ACE_HAS_SIG_C_FUNC */ + ACE_Object_Manager::at_thread_exit (instance_); #endif /* 0 */ } } - return ACE_TSS_GET (instance_, TYPE); #else // Perform the Double-Check pattern... - if (ACE_TSS_Singleton<TYPE, LOCK>::instance_ == 0) + if (singleton_ == 0) { ACE_GUARD_RETURN (LOCK, ace_mon, (ACE_TSS_Singleton<TYPE, LOCK>::ace_singleton_lock_), 0); - if (ACE_TSS_Singleton<TYPE, LOCK>::instance_ == 0) + if (singleton_ == 0) { - // "instance_" is not fully qualified in the following - // statement to avoid confusion with commas in macros. - // It is: ACE_TSS_Singleton<TYPE, LOCK>::instance_ - // if ( ACE_TSS_Singleton < TYPE == 0 ) { ( * ( ___errno ( ) ) ) = - - ACE_NEW_RETURN (instance_, ACE_TSS<TYPE>, 0); + ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, LOCK>), 0); #if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */ // Register for destruction with ACE_Object_Manager. -#if defined (ACE_HAS_SIG_C_FUNC) - ACE_Object_Manager::at_thread_exit (instance_, - ACE_Singleton_cleanup, - 0); -#else - ACE_Object_Manager::at_thread_exit (instance_, cleanup, 0); -#endif /* ACE_HAS_SIG_C_FUNC */ + ACE_Object_Manager::at_thread_exit (instance_); #endif /* 0 */ } } - return ACE_TSS_GET ((ACE_TSS_Singleton<TYPE, LOCK>::instance_), TYPE); - #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ + + return ACE_TSS_GET (singleton_->instance_, TYPE); } template <class TYPE, class LOCK> void -ACE_TSS_Singleton<TYPE, LOCK>::cleanup (void *object, void *) +ACE_TSS_Singleton<TYPE, LOCK>::cleanup (void *) { ACE_TRACE ("ACE_TSS_Singleton::cleanup"); - delete (TYPE *) object; + if (this->instance_ != 0) + { + delete this->instance_; + this->instance_ = 0; + + delete this; + } } #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Pointer to the Singleton instance. -template <class TYPE, class LOCK> ACE_TSS<TYPE> * -ACE_TSS_Singleton<TYPE, LOCK>::instance_ = 0; +template <class TYPE, class LOCK> ACE_TSS_Singleton <TYPE, LOCK> * +ACE_TSS_Singleton<TYPE, LOCK>::singleton_ = 0; // Lock the creation of the singleton. template <class TYPE, class LOCK> LOCK diff --git a/ace/Singleton.h b/ace/Singleton.h index 5c4510d2922..a61286605bd 100644 --- a/ace/Singleton.h +++ b/ace/Singleton.h @@ -22,7 +22,7 @@ #include "ace/Synch.h" template <class TYPE, class LOCK> -class ACE_Singleton +class ACE_Singleton : public ACE_Cleanup // = TITLE // A Singleton Adapter. // @@ -37,22 +37,28 @@ public: static TYPE *instance (TYPE*); // Set the Singleton instance. - static void cleanup (void *object, void *); - // Cleanup method, used by ACE_Object_Manager to destroy the singleton. + virtual void cleanup (void *param = 0); + // Cleanup method, used by ace_cleanup_destroyer to destroy the singleton. static void dump (void); // Dump the state of the object. protected: + ACE_Singleton (void) : instance_ (new TYPE) {} + // Default constructor. + + TYPE *instance_; + // Contained instance pointer. + #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - static TYPE *instance_; - // Pointer to the Singleton instance. + static ACE_Singleton<TYPE, LOCK> *singleton_; + // Pointer to the Singleton (ACE_Cleanup) instance. static LOCK ace_singleton_lock_; // Lock the creation of the singleton. #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ - static TYPE *&instance_i (void); + static ACE_Singleton<TYPE, LOCK> *&instance_i (void); // Get pointer to the Singleton instance static LOCK &singleton_lock_i (void); @@ -60,7 +66,7 @@ protected: }; template <class TYPE, class LOCK> -class ACE_TSS_Singleton +class ACE_TSS_Singleton : public ACE_Cleanup // = TITLE // A Thread Specific Storage Singleton Adapter. // @@ -72,16 +78,22 @@ public: static TYPE *instance (void); // Global access point to the Singleton. - static void cleanup (void *object, void *); - // Cleanup method, used by ACE_Object_Manager to destroy the singleton. + virtual void cleanup (void *param = 0); + // Cleanup method, used by ace_cleanup_destroyer to destroy the singleton. static void dump (void); // Dump the state of the object. protected: + ACE_TSS_Singleton (void) : instance_ (new ACE_TSS<TYPE>) {} + // Default constructor. + + ACE_TSS<TYPE> *instance_; + // Contained instance pointer. + #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - static ACE_TSS<TYPE> *instance_; - // Pointer to the Singleton instance. + static ACE_TSS_Singleton<TYPE, LOCK> *singleton_; + // Pointer to the Singleton (ACE_Cleanup) instance. static LOCK ace_singleton_lock_; // Lock the creation of the singleton. diff --git a/ace/Token_Invariants.cpp b/ace/Token_Invariants.cpp index e9c012b95a6..3c48a3991c3 100644 --- a/ace/Token_Invariants.cpp +++ b/ace/Token_Invariants.cpp @@ -28,39 +28,13 @@ ACE_Token_Invariant_Manager::instance (void) ACE_NEW_RETURN (instance_, ACE_Token_Invariant_Manager, 0); // Register for destruction with ACE_Object_Manager. -#if defined ACE_HAS_SIG_C_FUNC - ACE_Object_Manager::at_exit (instance_, - ACE_Token_Invariant_Manager_cleanup, - 0); -#else - ACE_Object_Manager::at_exit (instance_, - ACE_Token_Invariant_Manager::cleanup, - 0); -#endif /* ACE_HAS_SIG_C_FUNC */ + ACE_Object_Manager::at_exit (instance_); } } return instance_; } -#if defined (ACE_HAS_SIG_C_FUNC) -extern "C" void -ACE_Token_Invariant_Manager_cleanup (void *instance, void *) -{ - ACE_TRACE ("ACE_Token_Invariant_Manager_cleanup"); - - delete (ACE_Token_Invariant_Manager *) instance; -} -#else -void -ACE_Token_Invariant_Manager::cleanup (void *instance, void *) -{ - ACE_TRACE ("ACE_Token_Invariant_Manager::cleanup"); - - delete (ACE_Token_Invariant_Manager *) instance; -} -#endif /* ACE_HAS_SIG_C_FUNC */ - ACE_Token_Invariant_Manager::ACE_Token_Invariant_Manager (void) { ACE_TRACE ("ACE_Token_Invariant_Manager::ACE_Token_Invariant_Manager"); diff --git a/ace/Token_Invariants.h b/ace/Token_Invariants.h index b21f49a3725..f60947f9a30 100644 --- a/ace/Token_Invariants.h +++ b/ace/Token_Invariants.h @@ -104,7 +104,7 @@ private: // Number of owning readers. }; -class ACE_Export ACE_Token_Invariant_Manager +class ACE_Export ACE_Token_Invariant_Manager : public ACE_Cleanup // = TITLE // Token Invariants // @@ -122,9 +122,6 @@ public: static ACE_Token_Invariant_Manager *instance (void); // Singleton access point. - static void cleanup (void *instance, void *); - // Cleanup method, used by ACE_Object_Manager to destroy the singleton. - // = Polymorphic methods. Just pass in the proxy and the method // figures out the type of the token. @@ -164,7 +161,7 @@ public: ACE_Token_Invariant_Manager (void); // Prevent non-singleton construction. - ~ACE_Token_Invariant_Manager (void); + virtual ~ACE_Token_Invariant_Manager (void); // Destruction. protected: diff --git a/ace/Token_Manager.cpp b/ace/Token_Manager.cpp index 15cba017746..2f68e96afdf 100644 --- a/ace/Token_Manager.cpp +++ b/ace/Token_Manager.cpp @@ -52,39 +52,13 @@ ACE_Token_Manager::instance (void) ACE_NEW_RETURN (token_manager_, ACE_Token_Manager, 0); // Register for destruction with ACE_Object_Manager. -#if defined ACE_HAS_SIG_C_FUNC - ACE_Object_Manager::at_exit (token_manager_, - ACE_Token_Manager_cleanup, - 0); -#else - ACE_Object_Manager::at_exit (token_manager_, - ACE_Token_Manager::cleanup, - 0); -#endif /* ACE_HAS_SIG_C_FUNC */ + ACE_Object_Manager::at_exit (token_manager_); } } return token_manager_; } -#if defined (ACE_HAS_SIG_C_FUNC) -extern "C" void -ACE_Token_Manager_cleanup (void *instance, void *) -{ - ACE_TRACE ("ACE_Token_Manager_cleanup"); - - delete (ACE_Token_Manager *) instance; -} -#else -void -ACE_Token_Manager::cleanup (void *instance, void *) -{ - ACE_TRACE ("ACE_Token_Manager::cleanup"); - - delete (ACE_Token_Manager *) instance; -} -#endif /* ACE_HAS_SIG_C_FUNC */ - void ACE_Token_Manager::get_token (ACE_Token_Proxy *proxy, const char *token_name) diff --git a/ace/Token_Manager.h b/ace/Token_Manager.h index 0abcd82ab23..0a01df6c436 100644 --- a/ace/Token_Manager.h +++ b/ace/Token_Manager.h @@ -25,7 +25,7 @@ class ACE_Local_Mutex; class ACE_Mutex_Token; -class ACE_Export ACE_Token_Manager +class ACE_Export ACE_Token_Manager : ACE_Cleanup // = TITLE // Manages all tokens in a process space. // @@ -44,15 +44,12 @@ class ACE_Export ACE_Token_Manager { public: ACE_Token_Manager (void); - ~ACE_Token_Manager (void); + virtual ~ACE_Token_Manager (void); // Set/get a pointer to token manager singleton. static ACE_Token_Manager *instance (void); void instance (ACE_Token_Manager *); - static void cleanup (void *instance, void *); - // Cleanup method, used by ACE_Object_Manager to destroy the singleton. - void get_token (ACE_Token_Proxy *, const char *token_name); // The Token manager uses ACE_Token_Proxy::token_id_ to look for // an existing token. If none is found, the Token Manager calls |