ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK > Class Template Reference

Same as ACE_TSS_Singleton, except does _not_ register with ACE_Object_Manager for destruction. More...

#include <Singleton.h>

Inheritance diagram for ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >:

Inheritance graph
[legend]
Collaboration diagram for ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >:

Collaboration graph
[legend]
List of all members.

Static Public Member Functions

TYPE * instance (void)
 Global access point to the singleton.

void close (void)
 Explicitly delete the singleton instance.

void dump (void)
 Dump the state of the object.


Protected Member Functions

 ACE_Unmanaged_TSS_Singleton (void)
 Default constructor.


Static Protected Member Functions

ACE_Unmanaged_TSS_Singleton<
TYPE, ACE_LOCK > *& 
instance_i (void)
 Get pointer to the Singleton instance.


Static Protected Attributes

ACE_Unmanaged_TSS_Singleton<
TYPE, ACE_LOCK > * 
singleton_ = 0
 Pointer to the Singleton (ACE_Cleanup) instance.


Detailed Description

template<class TYPE, class ACE_LOCK>
class ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >

Same as ACE_TSS_Singleton, except does _not_ register with ACE_Object_Manager for destruction.

This version of ACE_TSS_Singleton can be used if, for example, its DLL will be unloaded before the ACE_Object_Manager destroys the instance. Unlike with ACE_Singleton, the application is responsible for explicitly destroying the instance after it is no longer needed (if it wants to avoid memory leaks, at least). The close() static member function must be used to explicitly destroy the Singleton.

Definition at line 216 of file Singleton.h.


Constructor & Destructor Documentation

template<class TYPE, class ACE_LOCK>
ACE_INLINE ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::ACE_Unmanaged_TSS_Singleton void   )  [protected]
 

Default constructor.

Definition at line 28 of file Singleton.inl.

00029 {
00030 }


Member Function Documentation

template<class TYPE, class ACE_LOCK>
void ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::close void   )  [static]
 

Explicitly delete the singleton instance.

Definition at line 381 of file Singleton.cpp.

References ACE_TSS_Singleton< TYPE, ACE_LOCK >::cleanup(), and ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance_i().

00382 {
00383   ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00384     ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00385 
00386   if (singleton)
00387     singleton->cleanup ();
00388 }

template<class TYPE, class ACE_LOCK>
void ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::dump void   )  [static]
 

Dump the state of the object.

Reimplemented from ACE_TSS_Singleton< TYPE, ACE_LOCK >.

Definition at line 303 of file Singleton.cpp.

References ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.

00304 {
00305 #if defined (ACE_HAS_DUMP)
00306   ACE_TRACE ("ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::dump");
00307 
00308 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00309   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("instance_ = %x"),
00310               ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00311   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00312 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00313 #endif /* ACE_HAS_DUMP */
00314 }

template<class TYPE, class ACE_LOCK>
TYPE * ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance void   )  [static]
 

Global access point to the singleton.

Reimplemented from ACE_TSS_Singleton< TYPE, ACE_LOCK >.

Definition at line 332 of file Singleton.cpp.

References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, ACE_TSS_GET, ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance_i(), ACE_Object_Manager::shutting_down(), and ACE_Object_Manager::starting_up().

00333 {
00334   ACE_TRACE ("ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance");
00335 
00336   ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00337     ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00338 
00339   // Perform the Double-Check pattern...
00340   if (singleton == 0)
00341     {
00342       if (ACE_Object_Manager::starting_up () ||
00343           ACE_Object_Manager::shutting_down ())
00344         {
00345           // The program is still starting up, and therefore assumed
00346           // to be single threaded.  There's no need to double-check.
00347           // Or, the ACE_Object_Manager instance has been destroyed,
00348           // so the preallocated lock is not available.  Either way,
00349           // don't register for destruction with the
00350           // ACE_Object_Manager:  we'll have to leak this instance.
00351 
00352           ACE_NEW_RETURN (singleton,
00353                           (ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>),
00354                           0);
00355         }
00356       else
00357         {
00358 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00359           // Obtain a lock from the ACE_Object_Manager.  The pointer
00360           // is static, so we only obtain one per
00361           // ACE_Unmanaged_Singleton instantiation.
00362           static ACE_LOCK *lock = 0;
00363           if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00364             // Failed to acquire the lock!
00365             return 0;
00366 
00367           ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00368 #endif /* ACE_MT_SAFE */
00369 
00370           if (singleton == 0)
00371             ACE_NEW_RETURN (singleton,
00372                             (ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>),
00373                             0);
00374         }
00375     }
00376 
00377   return ACE_TSS_GET (&singleton->instance_, TYPE);
00378 }

template<class TYPE, class ACE_LOCK>
ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK > *& ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance_i void   )  [static, protected]
 

Get pointer to the Singleton instance.

Reimplemented from ACE_TSS_Singleton< TYPE, ACE_LOCK >.

Definition at line 318 of file Singleton.cpp.

Referenced by ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::close(), and ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::instance().

00319 {
00320 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00321   // Pointer to the Singleton instance.  This works around a bug with
00322   // G++ and it's (mis-)handling of templates and statics...
00323   static ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00324 
00325   return singleton_;
00326 #else
00327   return ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::singleton_;
00328 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00329 }


Member Data Documentation

template<class TYPE, class ACE_LOCK>
ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK > * ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::singleton_ = 0 [static, protected]
 

Pointer to the Singleton (ACE_Cleanup) instance.

Reimplemented from ACE_TSS_Singleton< TYPE, ACE_LOCK >.

Definition at line 397 of file Singleton.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:32:17 2006 for ACE by doxygen 1.3.6