#include <Singleton.h>
Inheritance diagram for ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >:


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_Singleton (void) | |
| Default constructor. | |
Static Protected Member Functions | |
| ACE_Unmanaged_Singleton< TYPE, ACE_LOCK > *& | instance_i (void) |
| Get pointer to the Singleton instance. | |
Static Protected Attributes | |
| ACE_Unmanaged_Singleton< TYPE, ACE_LOCK > * | singleton_ = 0 |
| Pointer to the Singleton (ACE_Cleanup) instance. | |
This version of ACE_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. 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 126 of file Singleton.h.
|
||||||||||
|
Default constructor.
Definition at line 18 of file Singleton.inl.
00019 {
00020 }
|
|
||||||||||
|
Explicitly delete the Singleton instance.
Definition at line 202 of file Singleton.cpp. References ACE_Singleton< TYPE, ACE_LOCK >::cleanup(), and ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::instance_i().
00203 {
00204 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *&singleton =
00205 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ();
00206
00207 if (singleton)
00208 {
00209 singleton->cleanup ();
00210 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00211 }
00212 }
|
|
||||||||||
|
Dump the state of the object.
Reimplemented from ACE_Singleton< TYPE, ACE_LOCK >. Definition at line 125 of file Singleton.cpp. References ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00126 {
00127 #if defined (ACE_HAS_DUMP)
00128 ACE_TRACE ("ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::dump");
00129
00130 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00131 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00132 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00133 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00134 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00135 #endif /* ACE_HAS_DUMP */
00136 }
|
|
||||||||||
|
Global access point to the Singleton.
Reimplemented from ACE_Singleton< TYPE, ACE_LOCK >. Definition at line 154 of file Singleton.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, ACE_Singleton< TYPE, ACE_LOCK >::instance_, ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::instance_i(), ACE_Object_Manager::shutting_down(), and ACE_Object_Manager::starting_up().
00155 {
00156 ACE_TRACE ("ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance");
00157
00158 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *&singleton =
00159 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ();
00160
00161 // Perform the Double-Check pattern...
00162 if (singleton == 0)
00163 {
00164 if (ACE_Object_Manager::starting_up () ||
00165 ACE_Object_Manager::shutting_down ())
00166 {
00167 // The program is still starting up, and therefore assumed
00168 // to be single threaded. There's no need to double-check.
00169 // Or, the ACE_Object_Manager instance has been destroyed,
00170 // so the preallocated lock is not available. Either way,
00171 // don't register for destruction with the
00172 // ACE_Object_Manager: we'll have to leak this instance.
00173
00174 ACE_NEW_RETURN (singleton, (ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>),
00175 0);
00176 }
00177 else
00178 {
00179 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00180 // Obtain a lock from the ACE_Object_Manager. The pointer
00181 // is static, so we only obtain one per
00182 // ACE_Unmanaged_Singleton instantiation.
00183 static ACE_LOCK *lock = 0;
00184 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00185 // Failed to acquire the lock!
00186 return 0;
00187
00188 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00189 #endif /* ACE_MT_SAFE */
00190
00191 if (singleton == 0)
00192 ACE_NEW_RETURN (singleton,
00193 (ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>),
00194 0);
00195 }
00196 }
00197
00198 return &singleton->instance_;
00199 }
|
|
||||||||||
|
Get pointer to the Singleton instance.
Reimplemented from ACE_Singleton< TYPE, ACE_LOCK >. Definition at line 140 of file Singleton.cpp. Referenced by ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::close(), and ACE_Unmanaged_Singleton< TYPE, ACE_LOCK >::instance().
00141 {
00142 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00143 // Pointer to the Singleton instance. This works around a bug with
00144 // G++ and it's (mis-)handling of templates and statics...
00145 static ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00146
00147 return singleton_;
00148 #else
00149 return ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::singleton_;
00150 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00151 }
|
|
|||||
|
Pointer to the Singleton (ACE_Cleanup) instance.
Reimplemented from ACE_Singleton< TYPE, ACE_LOCK >. Definition at line 121 of file Singleton.cpp. |
1.3.6