TAO_Singleton< TYPE, ACE_LOCK > Class Template Reference

TAO-specific Singleton class. More...

#include <TAO_Singleton.h>

Inheritance diagram for TAO_Singleton< TYPE, ACE_LOCK >:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void cleanup (void *param=0)

Static Public Member Functions

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

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


Protected Member Functions

 TAO_Singleton (void)
 Default constructor.


Static Protected Member Functions

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


Protected Attributes

TYPE instance_
 Contained instance.


Static Protected Attributes

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


Detailed Description

template<class TYPE, class ACE_LOCK>
class TAO_Singleton< TYPE, ACE_LOCK >

TAO-specific Singleton class.

TAO_Singletons are used by TAO to register TAO-specific singleton instances with the TAO_Object_Manager. This ensures that TAO singletons are isolated from ACE's Object_Manager, thus allowing TAO to be safely dynamically unloaded.

Definition at line 47 of file TAO_Singleton.h.


Constructor & Destructor Documentation

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

Default constructor.

Definition at line 14 of file TAO_Singleton.inl.

00015 {
00016 }


Member Function Documentation

template<class TYPE, class ACE_LOCK>
void TAO_Singleton< TYPE, ACE_LOCK >::cleanup void *  param = 0  )  [virtual]
 

Cleanup method, used by to destroy the singleton.

Reimplemented from ACE_Cleanup.

Definition at line 105 of file TAO_Singleton.cpp.

References TAO_Singleton< TYPE, ACE_LOCK >::instance_i().

00106 {
00107   delete this;
00108   TAO_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00109 }

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

Dump the state of the object.

Definition at line 27 of file TAO_Singleton.cpp.

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

00028 {
00029   ACE_TRACE ("TAO_Singleton<TYPE, ACE_LOCK>::dump");
00030 
00031 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00032   ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("instance_ = %x"),
00033               TAO_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00034   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00035 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00036 }

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

Global access point to the Singleton.

Definition at line 53 of file TAO_Singleton.cpp.

References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, TAO_Singleton_Manager::at_exit(), TAO_Singleton< TYPE, ACE_LOCK >::instance_, TAO_Singleton< TYPE, ACE_LOCK >::instance_i(), TAO_Singleton_Manager::shutting_down(), and TAO_Singleton_Manager::starting_up().

Referenced by TAO::ORB_Table::instance().

00054 {
00055   ACE_TRACE ("TAO_Singleton<TYPE, ACE_LOCK>::instance");
00056 
00057   TAO_Singleton<TYPE, ACE_LOCK> *&singleton =
00058     TAO_Singleton<TYPE, ACE_LOCK>::instance_i ();
00059 
00060   // Perform the Double-Check pattern...
00061   if (singleton == 0)
00062     {
00063       if (TAO_Singleton_Manager::starting_up () ||
00064           TAO_Singleton_Manager::shutting_down ())
00065         {
00066           // The program is still starting up, and therefore assumed
00067           // to be single threaded.  There's no need to double-check.
00068           // Or, the TAO_Singleton_Manager instance has been destroyed,
00069           // so the preallocated lock is not available.  Either way,
00070           // don't register for destruction with the
00071           // TAO_Singleton_Manager:  we'll have to leak this instance.
00072 
00073           ACE_NEW_RETURN (singleton, (TAO_Singleton<TYPE, ACE_LOCK>), 0);
00074         }
00075       else
00076         {
00077 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00078           // Obtain a lock from the ACE_Object_Manager.  The pointer
00079           // is static, so we only obtain one per TAO_Singleton
00080           // instantiation.
00081           static ACE_LOCK *lock = 0;
00082           if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00083             // Failed to acquire the lock!
00084             return 0;
00085 
00086           ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00087 
00088           if (singleton == 0)
00089             {
00090 #endif /* ACE_MT_SAFE */
00091               ACE_NEW_RETURN (singleton, (TAO_Singleton<TYPE, ACE_LOCK>), 0);
00092 
00093               // Register for destruction with TAO_Singleton_Manager.
00094               TAO_Singleton_Manager::at_exit (singleton);
00095 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00096             }
00097 #endif /* ACE_MT_SAFE */
00098         }
00099     }
00100 
00101   return &singleton->instance_;
00102 }

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

Get pointer to the TAO Singleton instance.

Definition at line 39 of file TAO_Singleton.cpp.

Referenced by TAO_Singleton< TYPE, ACE_LOCK >::cleanup(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().

00040 {
00041 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00042   // Pointer to the Singleton instance.  This works around a bug with
00043   // G++ and it's (mis-)handling of templates and statics...
00044   static TAO_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00045 
00046   return singleton_;
00047 #else
00048   return TAO_Singleton<TYPE, ACE_LOCK>::singleton_;
00049 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00050 }


Member Data Documentation

template<class TYPE, class ACE_LOCK>
TYPE TAO_Singleton< TYPE, ACE_LOCK >::instance_ [protected]
 

Contained instance.

Definition at line 66 of file TAO_Singleton.h.

Referenced by TAO_Singleton< TYPE, ACE_LOCK >::instance().

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

Pointer to the Singleton (ACE_Cleanup) instance.

Definition at line 114 of file TAO_Singleton.cpp.


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 12:23:37 2006 for TAO by doxygen 1.3.6