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


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 | |
| ACE_TSS_Singleton (void) | |
| Default constructor. | |
| ACE_TSS_TYPE (TYPE) instance_ | |
| Contained instance. | |
| void | operator= (const ACE_TSS_Singleton< TYPE, ACE_LOCK > &) |
| ACE_TSS_Singleton (const ACE_TSS_Singleton< TYPE, ACE_LOCK > &) | |
Static Protected Member Functions | |
| ACE_TSS_Singleton< TYPE, ACE_LOCK > *& | instance_i (void) |
| Get pointer to the TSS Singleton instance. | |
Static Protected Attributes | |
| ACE_TSS_Singleton< TYPE, ACE_LOCK > * | singleton_ = 0 |
| Pointer to the Singleton (ACE_Cleanup) instance. | |
This implementation is another variation on the GoF Singleton pattern. In this case, a single <ACE_TSS_Singleton<TYPE, LOCK> > instance is allocated here, not a instance. Each call to the static method returns a Singleton whose pointer resides in thread-specific storage. As with ACE_Singleton, we use the ACE_Object_Manager so that the Singleton can be cleaned up when the process exits. For this scheme to work, a (static) cleanup() function must be provided. ACE_Singleton provides one so that TYPE doesn't need to.
Definition at line 170 of file Singleton.h.
|
||||||||||
|
Default constructor.
Definition at line 23 of file Singleton.inl.
00024 {
00025 }
|
|
||||||||||
|
|
|
||||||||||
|
Contained instance.
|
|
||||||||||
|
Cleanup method, used by to destroy the singleton. Reimplemented from ACE_Cleanup. Definition at line 296 of file Singleton.cpp. References ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance_i(). Referenced by ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >::close().
00297 {
00298 delete this;
00299 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00300 }
|
|
||||||||||
|
Dump the state of the object.
Reimplemented in ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >. Definition at line 215 of file Singleton.cpp. References ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, ACE_TRACE, and LM_DEBUG.
00216 {
00217 #if defined (ACE_HAS_DUMP)
00218 ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::dump");
00219
00220 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00221 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00222 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00223 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00224 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00225 #endif /* ACE_HAS_DUMP */
00226 }
|
|
||||||||||
|
Global access point to the singleton.
Reimplemented in ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >. Definition at line 243 of file Singleton.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_TRACE, ACE_TSS_GET, ACE_Object_Manager::at_exit(), ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance_i(), ACE_Object_Manager::shutting_down(), and ACE_Object_Manager::starting_up(). Referenced by ACE_Dynamic::instance().
00244 {
00245 ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance");
00246
00247 ACE_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00248 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00249
00250 // Perform the Double-Check pattern...
00251 if (singleton == 0)
00252 {
00253 if (ACE_Object_Manager::starting_up () ||
00254 ACE_Object_Manager::shutting_down ())
00255 {
00256 // The program is still starting up, and therefore assumed
00257 // to be single threaded. There's no need to double-check.
00258 // Or, the ACE_Object_Manager instance has been destroyed,
00259 // so the preallocated lock is not available. Either way,
00260 // don't register for destruction with the
00261 // ACE_Object_Manager: we'll have to leak this instance.
00262
00263 ACE_NEW_RETURN (singleton, (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0);
00264 }
00265 else
00266 {
00267 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00268
00269 // Obtain a lock from the ACE_Object_Manager. The pointer
00270 // is static, so we only obtain one per ACE_Singleton instantiation.
00271 static ACE_LOCK *lock = 0;
00272 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00273 // Failed to acquire the lock!
00274 return 0;
00275
00276 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00277
00278 if (singleton == 0)
00279 {
00280 #endif /* ACE_MT_SAFE */
00281 ACE_NEW_RETURN (singleton, (ACE_TSS_Singleton<TYPE, ACE_LOCK>),
00282 0);
00283
00284 // Register for destruction with ACE_Object_Manager.
00285 ACE_Object_Manager::at_exit (singleton);
00286 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00287 }
00288 #endif /* ACE_MT_SAFE */
00289 }
00290 }
00291
00292 return ACE_TSS_GET (&singleton->instance_, TYPE);
00293 }
|
|
||||||||||
|
Get pointer to the TSS Singleton instance.
Reimplemented in ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >. Definition at line 229 of file Singleton.cpp. Referenced by ACE_TSS_Singleton< TYPE, ACE_LOCK >::cleanup(), and ACE_TSS_Singleton< TYPE, ACE_LOCK >::instance().
00230 {
00231 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00232 // Pointer to the Singleton instance. This works around a bug with
00233 // G++ and it's (mis-)handling of templates and statics...
00234 static ACE_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00235
00236 return singleton_;
00237 #else
00238 return ACE_TSS_Singleton<TYPE, ACE_LOCK>::singleton_;
00239 #endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
00240 }
|
|
||||||||||
|
|
|
|||||
|
Pointer to the Singleton (ACE_Cleanup) instance.
Reimplemented in ACE_Unmanaged_TSS_Singleton< TYPE, ACE_LOCK >. Definition at line 393 of file Singleton.cpp. |
1.3.6