#include <Singleton.h>
Collaboration diagram for ACE_DLL_Singleton_T< TYPE, ACE_LOCK >:

Public Member Functions | |
| const ACE_TCHAR * | dll_name (void) |
| const ACE_TCHAR * | name (void) |
Static Public Member Functions | |
| TYPE * | instance (void) |
| Global access point to the Singleton. | |
| void | close (void) |
| Explicitly delete the Singleton instance. | |
| void | close_singleton (void) |
| void | dump (void) |
| Dump the state of the object. | |
Protected Member Functions | |
| ACE_DLL_Singleton_T (void) | |
| Default constructor. | |
| ~ACE_DLL_Singleton_T (void) | |
| Destructor. | |
Static Protected Member Functions | |
| ACE_DLL_Singleton_T< TYPE, ACE_LOCK > *& | instance_i (void) |
| Get pointer to the singleton instance. | |
Protected Attributes | |
| TYPE | instance_ |
| Contained instance. | |
Static Protected Attributes | |
| ACE_DLL_Singleton_T< TYPE, ACE_LOCK > * | singleton_ = 0 |
| Pointer to the Singleton instance. | |
This version of ACE_Singleton should be used for singletons that live in a dll loaded either directly by ACE_DLL or indirectly by the ACE Service Configuration framework. Whenever ACE_DLL is ready to actually unload the dll, ACE_DLL_Singleton based dlls associated with that dll will be destroyed first. In fact, any singleton can safely use ACE_DLL_Singleton, even those that don't live in dlls. In that case, the singleton will be destroyed at normal program shutdown.
The only additional requirement is that the contained class export name() and dll_name() methods. See ACE_DLL_Singleton_Adapter_T below for a convenient example of how to satisfy this requirement for the dll_name().
Usage is the same as for ACE_Singleton, but note that if you you declare a friend, the friend class must still be an *ACE_Singleton*<T, [ACE_LOCK]>, not an ACE_Unmanaged_Singleton.
Definition at line 266 of file Singleton.h.
|
||||||||||
|
Default constructor.
Definition at line 33 of file Singleton.inl.
00034 {
00035 }
|
|
||||||||||
|
Destructor.
Definition at line 38 of file Singleton.inl.
00039 {
00040 }
|
|
||||||||||
|
Explicitly delete the Singleton instance.
Definition at line 491 of file Singleton.cpp. References ACE_TRACE, and ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance_i(). Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::close_singleton().
00492 {
00493 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close");
00494
00495 ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
00496 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();
00497
00498 delete singleton;
00499 singleton = 0;
00500 }
|
|
||||||||||
|
Definition at line 503 of file Singleton.cpp. References ACE_TRACE, and ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::close().
00504 {
00505 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close_singleton");
00506 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close ();
00507 }
|
|
||||||||||
|
Definition at line 510 of file Singleton.cpp. References ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance().
00511 {
00512 return this->instance ()->dll_name ();
00513 }
|
|
||||||||||
|
Dump the state of the object.
Definition at line 409 of file Singleton.cpp. References ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00410 {
00411 #if defined (ACE_HAS_DUMP)
00412 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::dump");
00413
00414 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00415 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00416 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ()));
00417 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00418 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00419 #endif /* ACE_HAS_DUMP */
00420 }
|
|
||||||||||
|
Global access point to the Singleton.
Definition at line 440 of file Singleton.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, ACE_Framework_Repository::instance(), ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance_, ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance_i(), ACE_Framework_Repository::register_component(), ACE_Object_Manager::shutting_down(), and ACE_Object_Manager::starting_up(). Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::dll_name(), and ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::name().
00441 {
00442 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance");
00443
00444 ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
00445 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();
00446
00447 // Perform the Double-Check pattern...
00448 if (singleton == 0)
00449 {
00450 if (ACE_Object_Manager::starting_up () ||
00451 ACE_Object_Manager::shutting_down ())
00452 {
00453 // The program is still starting up, and therefore assumed
00454 // to be single threaded. There's no need to double-check.
00455 // Or, the ACE_Object_Manager instance has been destroyed,
00456 // so the preallocated lock is not available. Either way,
00457 // don't register for destruction with the
00458 // ACE_Object_Manager: we'll have to leak this instance.
00459
00460 ACE_NEW_RETURN (singleton, (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
00461 0);
00462 }
00463 else
00464 {
00465 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00466 // Obtain a lock from the ACE_Object_Manager. The pointer
00467 // is static, so we only obtain one per
00468 // ACE_Unmanaged_Singleton instantiation.
00469 static ACE_LOCK *lock = 0;
00470 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00471 // Failed to acquire the lock!
00472 return 0;
00473
00474 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00475 #endif /* ACE_MT_SAFE */
00476
00477 if (singleton == 0)
00478 ACE_NEW_RETURN (singleton,
00479 (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
00480 0);
00481 }
00482 //ACE_REGISTER_FRAMEWORK_COMPONENT(ACE_DLL_Singleton<TYPE,ACE_LOCK>, singleton);
00483 ACE_Framework_Repository::instance ()->register_component
00484 (new ACE_Framework_Component_T<ACE_DLL_Singleton_T<TYPE, ACE_LOCK> > (singleton));
00485 }
00486
00487 return &singleton->instance_;
00488 }
|
|
||||||||||
|
Get pointer to the singleton instance.
Definition at line 424 of file Singleton.cpp. References ACE_TRACE. Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::close(), and ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance().
00425 {
00426 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i");
00427
00428 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00429 // Pointer to the Singleton instance. This works around a bug with
00430 // G++ and it's (mis-)handling of templates and statics...
00431 static ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *singleton_ = 0;
00432
00433 return singleton_;
00434 #else
00435 return ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::singleton_;
00436 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00437 }
|
|
||||||||||
|
Definition at line 516 of file Singleton.cpp. References ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance().
00517 {
00518 return this->instance ()->name ();
00519 }
|
|
|||||
|
Contained instance.
Definition at line 294 of file Singleton.h. Referenced by ACE_DLL_Singleton_T< TYPE, ACE_LOCK >::instance(). |
|
|||||
|
Pointer to the Singleton instance.
Definition at line 405 of file Singleton.cpp. |
1.3.6