diff options
author | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-22 21:34:03 +0000 |
---|---|---|
committer | levine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-10-22 21:34:03 +0000 |
commit | ab496543495cfa9599bb85dfac8acfd1cab889df (patch) | |
tree | 3be789bff0ab97153eea9548103f125117688578 /ace/Singleton.cpp | |
parent | 571aacd452f66485e60007e485f8844bc67436a0 (diff) | |
download | ATCD-ab496543495cfa9599bb85dfac8acfd1cab889df.tar.gz |
moved ace_singleton_lock_ to Object_Manager
Diffstat (limited to 'ace/Singleton.cpp')
-rw-r--r-- | ace/Singleton.cpp | 128 |
1 files changed, 67 insertions, 61 deletions
diff --git a/ace/Singleton.cpp b/ace/Singleton.cpp index 6b098b29791..62a712d9388 100644 --- a/ace/Singleton.cpp +++ b/ace/Singleton.cpp @@ -19,9 +19,8 @@ ACE_Singleton<TYPE, ACE_LOCK>::dump (void) ACE_TRACE ("ACE_Singleton<TYPE, ACE_LOCK>::dump"); #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - ACE_DEBUG ((LM_DEBUG, "instance_ = %x", + ACE_DEBUG ((LM_DEBUG, "instance_ = %x", ACE_Singleton<TYPE, ACE_LOCK>::instance_i ())); - ACE_Singleton<TYPE, ACE_LOCK>::singleton_lock_i ().dump (); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } @@ -40,40 +39,45 @@ ACE_Singleton<TYPE, ACE_LOCK>::instance_i (void) #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } -template <class TYPE, class ACE_LOCK> ACE_LOCK & -ACE_Singleton<TYPE, ACE_LOCK>::singleton_lock_i (void) -{ -#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - // Lock the creation of the singleton. This works around a - // "feature" of G++... ;-) - static ACE_LOCK ace_singleton_lock_; - - return ace_singleton_lock_; -#else - return ACE_Singleton<TYPE, ACE_LOCK>::ace_singleton_lock_; -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ -} - template <class TYPE, class ACE_LOCK> TYPE * ACE_Singleton<TYPE, ACE_LOCK>::instance (void) { ACE_TRACE ("ACE_Singleton<TYPE, ACE_LOCK>::instance"); - ACE_Singleton<TYPE, ACE_LOCK> *&singleton = + ACE_Singleton<TYPE, ACE_LOCK> *&singleton = ACE_Singleton<TYPE, ACE_LOCK>::instance_i (); // Perform the Double-Check pattern... if (singleton == 0) { - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_Singleton<TYPE, ACE_LOCK>::singleton_lock_i ()), 0); - - if (singleton == 0) +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) + if (ACE_Object_Manager::starting_up ()) { + // The program is still starting up, and therefore assumed + // to be single threaded. There's no need to double-check. +#endif /* ACE_MT_SAFE */ ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, ACE_LOCK>), 0); // Register for destruction with ACE_Object_Manager. ACE_Object_Manager::at_exit (singleton); +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) } + else + { + // Use the Object_Manager's preallocated lock. + ACE_LOCK *lock = + ACE_Object_Manager::get_singleton_lock ((ACE_LOCK *) 0); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0); + + if (singleton == 0) + { + ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, ACE_LOCK>), 0); + + // Register for destruction with ACE_Object_Manager. + ACE_Object_Manager::at_exit (singleton); + } + } +#endif /* ACE_MT_SAFE */ } return &singleton->instance_; @@ -89,10 +93,6 @@ ACE_Singleton<TYPE, ACE_LOCK>::cleanup (void *) // Pointer to the Singleton instance. template <class TYPE, class ACE_LOCK> ACE_Singleton<TYPE, ACE_LOCK> * ACE_Singleton<TYPE, ACE_LOCK>::singleton_ = 0; - -// Lock the creation of the singleton. -template <class TYPE, class ACE_LOCK> ACE_LOCK -ACE_Singleton<TYPE, ACE_LOCK>::ace_singleton_lock_; #endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */ template <class TYPE, class ACE_LOCK> void @@ -101,63 +101,73 @@ ACE_TSS_Singleton<TYPE, ACE_LOCK>::dump (void) ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::dump"); #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) - ACE_DEBUG ((LM_DEBUG, "instance_ = %x", &singleton_->instance_)); - ace_singleton_lock_.dump(); + ACE_DEBUG ((LM_DEBUG, "instance_ = %x", + ACE_Singleton<TYPE, ACE_LOCK>::instance_i ())); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ } -template <class TYPE, class ACE_LOCK> TYPE * -ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance (void) +template <class TYPE, class ACE_LOCK> ACE_TSS_Singleton<TYPE, ACE_LOCK> *& +ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i (void) { - ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance"); - #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) // Pointer to the Singleton instance. This works around a bug with - // G++... + // G++ and it's (mis-)handling of templates and statics... static ACE_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0; - // Lock the creation of the singleton. This works around a - // "feature" of G++... ;-) - static ACE_LOCK ace_singleton_lock_; + return singleton_; +#else + return ACE_TSS_Singleton<TYPE, ACE_LOCK>::singleton_; +#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ +} + +template <class TYPE, class ACE_LOCK> TYPE * +ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance (void) +{ + ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance"); - // Perform the Double-Check pattern... - if (singleton_ == 0) - { - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, ace_singleton_lock_, 0); + ACE_TSS_Singleton<TYPE, ACE_LOCK> *&singleton = + ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i (); - if (singleton_ == 0) + // Perform the Double-Check pattern... + if (singleton == 0) + { +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) + if (ACE_Object_Manager::starting_up ()) { - ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0); + // The program is still starting up, and therefore assumed + // to be single threaded. There's no need to double-check. +#endif /* ACE_MT_SAFE */ + ACE_NEW_RETURN (singleton, (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0); #if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */ // Register for destruction with ACE_Object_Manager. - ACE_Object_Manager::at_thread_exit (instance_); + ACE_Object_Manager::at_thread_exit (singleton); #endif /* 0 */ +#if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) } - } - -#else - - // Perform the Double-Check pattern... - if (singleton_ == 0) - { - ACE_GUARD_RETURN (ACE_LOCK, ace_mon, (ACE_TSS_Singleton<TYPE, ACE_LOCK>::ace_singleton_lock_), 0); - - if (singleton_ == 0) + else { - ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0); + // Use the Object_Manager's preallocated lock. + ACE_LOCK *lock = + ACE_Object_Manager::get_singleton_lock ((ACE_LOCK *) 0); + ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0); + + if (singleton == 0) + { + ACE_NEW_RETURN (singleton, + (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0); #if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */ - // Register for destruction with ACE_Object_Manager. - ACE_Object_Manager::at_thread_exit (instance_); + // Register for destruction with ACE_Object_Manager. + ACE_Object_Manager::at_thread_exit (singleton); #endif /* 0 */ + } } +#endif /* ACE_MT_SAFE */ } -#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */ - - return ACE_TSS_GET (&singleton_->instance_, TYPE); + return ACE_TSS_GET (&singleton->instance_, TYPE); } template <class TYPE, class ACE_LOCK> void @@ -172,10 +182,6 @@ ACE_TSS_Singleton<TYPE, ACE_LOCK>::cleanup (void *) // Pointer to the Singleton instance. template <class TYPE, class ACE_LOCK> ACE_TSS_Singleton <TYPE, ACE_LOCK> * ACE_TSS_Singleton<TYPE, ACE_LOCK>::singleton_ = 0; - -// Lock the creation of the singleton. -template <class TYPE, class ACE_LOCK> ACE_LOCK -ACE_TSS_Singleton<TYPE, ACE_LOCK>::ace_singleton_lock_; #endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */ #endif /* ACE_SINGLETON_C */ |