Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TAO_Singleton Class Template Reference

TAO-specific Singleton class. More...

#include <TAO_Singleton.h>

Inheritance diagram for TAO_Singleton:

Inheritance graph
[legend]
Collaboration diagram for TAO_Singleton:

Collaboration graph
[legend]
List of all members.

Public Methods

virtual void cleanup (void *param=0)
 Cleanup method, used by <ace_cleanup_destroyer> to destroy the singleton. More...


Static Public Methods

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

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


Protected Methods

 TAO_Singleton (void)
 Default constructor. More...


Static Protected Methods

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


Protected Attributes

TYPE instance_
 Contained instance. More...


Static Protected Attributes

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


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 41 of file TAO_Singleton.h.


Constructor & Destructor Documentation

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

Default constructor.

Definition at line 10 of file TAO_Singleton.inl.

00011 {
00012 }


Member Function Documentation

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

Cleanup method, used by <ace_cleanup_destroyer> to destroy the singleton.

Reimplemented from ACE_Cleanup.

Definition at line 106 of file TAO_Singleton.cpp.

References instance_i.

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

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

Dump the state of the object.

Definition at line 28 of file TAO_Singleton.cpp.

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

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

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

Global access point to the Singleton.

Definition at line 54 of file TAO_Singleton.cpp.

References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, TAO_Singleton_Manager::at_exit, instance_, instance_i, TAO_Singleton_Manager::shutting_down, and TAO_Singleton_Manager::starting_up.

Referenced by TAO_ORBInitializer_Registry::instance, TAO_ORB_Table::instance, and CORBA_ORB::register_value_factory.

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

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 40 of file TAO_Singleton.cpp.

References singleton_.

Referenced by cleanup, dump, and instance.

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


Member Data Documentation

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

Contained instance.

Definition at line 60 of file TAO_Singleton.h.

Referenced by 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 115 of file TAO_Singleton.cpp.

Referenced by instance_i.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 15:39:34 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002