00001
00002
00003 #ifndef ACE_SINGLETON_C
00004 #define ACE_SINGLETON_C
00005
00006 #include "ace/Singleton.h"
00007
00008 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00009 # pragma once
00010 #endif
00011
00012 #if !defined (__ACE_INLINE__)
00013 #include "ace/Singleton.i"
00014 #endif
00015
00016 #include "ace/Synch_T.h"
00017 #include "ace/Object_Manager.h"
00018 #include "ace/Log_Msg.h"
00019 #include "ace/Framework_Component.h"
00020
00021 ACE_RCSID (ace,
00022 Singleton,
00023 "$Id: Singleton.cpp,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $")
00024
00025 template <class TYPE, class ACE_LOCK> void
00026 ACE_Singleton<TYPE, ACE_LOCK>::dump (void)
00027 {
00028 ACE_TRACE ("ACE_Singleton<TYPE, ACE_LOCK>::dump");
00029
00030 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00031 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00032 ACE_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00033 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00034 #endif
00035 }
00036
00037 template <class TYPE, class ACE_LOCK> ACE_Singleton<TYPE, ACE_LOCK> *&
00038 ACE_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00039 {
00040 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00041
00042
00043 static ACE_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00044
00045 return singleton_;
00046 #else
00047 return ACE_Singleton<TYPE, ACE_LOCK>::singleton_;
00048 #endif
00049 }
00050
00051 template <class TYPE, class ACE_LOCK> TYPE *
00052 ACE_Singleton<TYPE, ACE_LOCK>::instance (void)
00053 {
00054 ACE_TRACE ("ACE_Singleton<TYPE, ACE_LOCK>::instance");
00055
00056 ACE_Singleton<TYPE, ACE_LOCK> *&singleton =
00057 ACE_Singleton<TYPE, ACE_LOCK>::instance_i ();
00058
00059
00060 if (singleton == 0)
00061 {
00062 if (ACE_Object_Manager::starting_up () ||
00063 ACE_Object_Manager::shutting_down ())
00064 {
00065
00066
00067
00068
00069
00070
00071
00072 ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, ACE_LOCK>), 0);
00073 }
00074 else
00075 {
00076 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00077
00078
00079
00080 static ACE_LOCK *lock = 0;
00081 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00082
00083 return 0;
00084
00085 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00086
00087 if (singleton == 0)
00088 {
00089 #endif
00090 ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, ACE_LOCK>), 0);
00091
00092
00093 ACE_Object_Manager::at_exit (singleton);
00094 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00095 }
00096 #endif
00097 }
00098 }
00099
00100 return &singleton->instance_;
00101 }
00102
00103 template <class TYPE, class ACE_LOCK> void
00104 ACE_Singleton<TYPE, ACE_LOCK>::cleanup (void *)
00105 {
00106 delete this;
00107 ACE_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00108 }
00109
00110 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00111
00112 template <class TYPE, class ACE_LOCK> ACE_Singleton<TYPE, ACE_LOCK> *
00113 ACE_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00114
00115 template <class TYPE, class ACE_LOCK> ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *
00116 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00117 #endif
00118
00119 template <class TYPE, class ACE_LOCK> void
00120 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::dump (void)
00121 {
00122 ACE_TRACE ("ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::dump");
00123
00124 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00125 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00126 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00127 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00128 #endif
00129 }
00130
00131 template <class TYPE, class ACE_LOCK>
00132 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *&
00133 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00134 {
00135 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00136
00137
00138 static ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00139
00140 return singleton_;
00141 #else
00142 return ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::singleton_;
00143 #endif
00144 }
00145
00146 template <class TYPE, class ACE_LOCK> TYPE *
00147 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance (void)
00148 {
00149 ACE_TRACE ("ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance");
00150
00151 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *&singleton =
00152 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ();
00153
00154
00155 if (singleton == 0)
00156 {
00157 if (ACE_Object_Manager::starting_up () ||
00158 ACE_Object_Manager::shutting_down ())
00159 {
00160
00161
00162
00163
00164
00165
00166
00167 ACE_NEW_RETURN (singleton, (ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>),
00168 0);
00169 }
00170 else
00171 {
00172 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00173
00174
00175
00176 static ACE_LOCK *lock = 0;
00177 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00178
00179 return 0;
00180
00181 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00182 #endif
00183
00184 if (singleton == 0)
00185 ACE_NEW_RETURN (singleton,
00186 (ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>),
00187 0);
00188 }
00189 }
00190
00191 return &singleton->instance_;
00192 }
00193
00194 template <class TYPE, class ACE_LOCK> void
00195 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::close (void)
00196 {
00197 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK> *&singleton =
00198 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i ();
00199
00200 if (singleton)
00201 {
00202 singleton->cleanup ();
00203 ACE_Unmanaged_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00204 }
00205 }
00206
00207 template <class TYPE, class ACE_LOCK> void
00208 ACE_TSS_Singleton<TYPE, ACE_LOCK>::dump (void)
00209 {
00210 ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::dump");
00211
00212 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00213 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00214 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00215 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00216 #endif
00217 }
00218
00219 template <class TYPE, class ACE_LOCK> ACE_TSS_Singleton<TYPE, ACE_LOCK> *&
00220 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00221 {
00222 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00223
00224
00225 static ACE_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00226
00227 return singleton_;
00228 #else
00229 return ACE_TSS_Singleton<TYPE, ACE_LOCK>::singleton_;
00230 #endif
00231 }
00232
00233 template <class TYPE, class ACE_LOCK> TYPE *
00234 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance (void)
00235 {
00236 ACE_TRACE ("ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance");
00237
00238 ACE_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00239 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00240
00241
00242 if (singleton == 0)
00243 {
00244 if (ACE_Object_Manager::starting_up () ||
00245 ACE_Object_Manager::shutting_down ())
00246 {
00247
00248
00249
00250
00251
00252
00253
00254 ACE_NEW_RETURN (singleton, (ACE_TSS_Singleton<TYPE, ACE_LOCK>), 0);
00255 }
00256 else
00257 {
00258 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00259
00260
00261
00262 static ACE_LOCK *lock = 0;
00263 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00264
00265 return 0;
00266
00267 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00268
00269 if (singleton == 0)
00270 {
00271 #endif
00272 ACE_NEW_RETURN (singleton, (ACE_TSS_Singleton<TYPE, ACE_LOCK>),
00273 0);
00274
00275
00276 ACE_Object_Manager::at_exit (singleton);
00277 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00278 }
00279 #endif
00280 }
00281 }
00282
00283 return ACE_TSS_GET (&singleton->instance_, TYPE);
00284 }
00285
00286 template <class TYPE, class ACE_LOCK> void
00287 ACE_TSS_Singleton<TYPE, ACE_LOCK>::cleanup (void *)
00288 {
00289 delete this;
00290 ACE_TSS_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00291 }
00292
00293 template <class TYPE, class ACE_LOCK> void
00294 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::dump (void)
00295 {
00296 ACE_TRACE ("ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::dump");
00297
00298 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00299 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00300 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00301 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00302 #endif
00303 }
00304
00305 template <class TYPE, class ACE_LOCK>
00306 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *&
00307 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00308 {
00309 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00310
00311
00312 static ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00313
00314 return singleton_;
00315 #else
00316 return ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::singleton_;
00317 #endif
00318 }
00319
00320 template <class TYPE, class ACE_LOCK> TYPE *
00321 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance (void)
00322 {
00323 ACE_TRACE ("ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance");
00324
00325 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00326 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00327
00328
00329 if (singleton == 0)
00330 {
00331 if (ACE_Object_Manager::starting_up () ||
00332 ACE_Object_Manager::shutting_down ())
00333 {
00334
00335
00336
00337
00338
00339
00340
00341 ACE_NEW_RETURN (singleton,
00342 (ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>),
00343 0);
00344 }
00345 else
00346 {
00347 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00348
00349
00350
00351 static ACE_LOCK *lock = 0;
00352 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00353
00354 return 0;
00355
00356 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00357 #endif
00358
00359 if (singleton == 0)
00360 ACE_NEW_RETURN (singleton,
00361 (ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>),
00362 0);
00363 }
00364 }
00365
00366 return ACE_TSS_GET (&singleton->instance_, TYPE);
00367 }
00368
00369 template <class TYPE, class ACE_LOCK> void
00370 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::close (void)
00371 {
00372 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00373 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00374
00375 if (singleton)
00376 singleton->cleanup ();
00377 }
00378
00379 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00380
00381 template <class TYPE, class ACE_LOCK> ACE_TSS_Singleton <TYPE, ACE_LOCK> *
00382 ACE_TSS_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00383
00384 template <class TYPE, class ACE_LOCK>
00385 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK> *
00386 ACE_Unmanaged_TSS_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00387 #endif
00388
00389
00390
00391 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00392
00393 template <class TYPE, class ACE_LOCK> ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *
00394 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::singleton_ = 0;
00395 #endif
00396
00397 template <class TYPE, class ACE_LOCK> void
00398 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::dump (void)
00399 {
00400 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::dump");
00401
00402 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00403 ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("instance_ = %x"),
00404 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ()));
00405 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00406 #endif
00407 }
00408
00409 template <class TYPE, class ACE_LOCK>
00410 ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&
00411 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i (void)
00412 {
00413 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i");
00414
00415 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00416
00417
00418 static ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *singleton_ = 0;
00419
00420 return singleton_;
00421 #else
00422 return ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::singleton_;
00423 #endif
00424 }
00425
00426 template <class TYPE, class ACE_LOCK> TYPE *
00427 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance (void)
00428 {
00429 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance");
00430
00431 ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
00432 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();
00433
00434
00435 if (singleton == 0)
00436 {
00437 if (ACE_Object_Manager::starting_up () ||
00438 ACE_Object_Manager::shutting_down ())
00439 {
00440
00441
00442
00443
00444
00445
00446
00447 ACE_NEW_RETURN (singleton, (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
00448 0);
00449 }
00450 else
00451 {
00452 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00453
00454
00455
00456 static ACE_LOCK *lock = 0;
00457 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00458
00459 return 0;
00460
00461 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00462 #endif
00463
00464 if (singleton == 0)
00465 ACE_NEW_RETURN (singleton,
00466 (ACE_DLL_Singleton_T<TYPE, ACE_LOCK>),
00467 0);
00468 }
00469
00470 ACE_Framework_Repository::instance ()->register_component
00471 (new ACE_Framework_Component_T<ACE_DLL_Singleton_T<TYPE, ACE_LOCK> > (singleton));
00472 }
00473
00474 return &singleton->instance_;
00475 }
00476
00477 template <class TYPE, class ACE_LOCK> void
00478 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close (void)
00479 {
00480 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close");
00481
00482 ACE_DLL_Singleton_T<TYPE, ACE_LOCK> *&singleton =
00483 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::instance_i ();
00484
00485 delete singleton;
00486 singleton = 0;
00487 }
00488
00489 template <class TYPE, class ACE_LOCK> void
00490 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close_singleton (void)
00491 {
00492 ACE_TRACE ("ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close_singleton");
00493 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::close ();
00494 }
00495
00496 template <class TYPE, class ACE_LOCK> const ACE_TCHAR *
00497 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::dll_name (void)
00498 {
00499 return this->instance ()->dll_name ();
00500 }
00501
00502 template <class TYPE, class ACE_LOCK> const ACE_TCHAR *
00503 ACE_DLL_Singleton_T<TYPE, ACE_LOCK>::name (void)
00504 {
00505 return this->instance ()->name ();
00506 }
00507
00508
00509
00510
00511 template <class TYPE> const ACE_TCHAR*
00512 ACE_DLL_Singleton_Adapter_T<TYPE>::dll_name (void)
00513 {
00514
00515
00516 return ACE_TEXT("ACE");
00517 }
00518
00519 #endif