00001
00002
00003
00004
00005 #ifndef TAO_SINGLETON_CPP
00006 #define TAO_SINGLETON_CPP
00007
00008 #include "tao/TAO_Singleton.h"
00009
00010 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00011 # pragma once
00012 #endif
00013
00014 #include "tao/TAO_Singleton_Manager.h"
00015
00016 #include "ace/Guard_T.h"
00017 #include "ace/Object_Manager.h"
00018 #include "ace/Log_Msg.h"
00019
00020 #if !defined (__ACE_INLINE__)
00021 #include "tao/TAO_Singleton.inl"
00022 #endif
00023
00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00025
00026 template <class TYPE, class ACE_LOCK> void
00027 TAO_Singleton<TYPE, ACE_LOCK>::dump (void)
00028 {
00029 ACE_TRACE ("TAO_Singleton<TYPE, ACE_LOCK>::dump");
00030
00031 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00032 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("instance_ = %x"),
00033 TAO_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00034 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00035 #endif
00036 }
00037
00038 template <class TYPE, class ACE_LOCK> TAO_Singleton<TYPE, ACE_LOCK> *&
00039 TAO_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00040 {
00041 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00042
00043
00044 static TAO_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00045
00046 return singleton_;
00047 #else
00048 return TAO_Singleton<TYPE, ACE_LOCK>::singleton_;
00049 #endif
00050 }
00051
00052 template <class TYPE, class ACE_LOCK> TYPE *
00053 TAO_Singleton<TYPE, ACE_LOCK>::instance (void)
00054 {
00055 ACE_TRACE ("TAO_Singleton<TYPE, ACE_LOCK>::instance");
00056
00057 TAO_Singleton<TYPE, ACE_LOCK> *&singleton =
00058 TAO_Singleton<TYPE, ACE_LOCK>::instance_i ();
00059
00060
00061 if (singleton == 0)
00062 {
00063 if (TAO_Singleton_Manager::starting_up () ||
00064 TAO_Singleton_Manager::shutting_down ())
00065 {
00066
00067
00068
00069
00070
00071
00072
00073 ACE_NEW_RETURN (singleton, (TAO_Singleton<TYPE, ACE_LOCK>), 0);
00074 }
00075 else
00076 {
00077 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00078
00079
00080
00081 static ACE_LOCK *lock = 0;
00082 if (ACE_Object_Manager::get_singleton_lock (lock) != 0)
00083
00084 return 0;
00085
00086 ACE_GUARD_RETURN (ACE_LOCK, ace_mon, *lock, 0);
00087
00088 if (singleton == 0)
00089 {
00090 #endif
00091 ACE_NEW_RETURN (singleton, (TAO_Singleton<TYPE, ACE_LOCK>), 0);
00092
00093
00094 TAO_Singleton_Manager::at_exit (singleton);
00095 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00096 }
00097 #endif
00098 }
00099 }
00100
00101 return &singleton->instance_;
00102 }
00103
00104 template <class TYPE, class ACE_LOCK> void
00105 TAO_Singleton<TYPE, ACE_LOCK>::cleanup (void *)
00106 {
00107 delete this;
00108 TAO_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00109 }
00110
00111 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00112
00113 template <class TYPE, class ACE_LOCK> TAO_Singleton<TYPE, ACE_LOCK> *
00114 TAO_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00115
00116 template <class TYPE, class ACE_LOCK> TAO_TSS_Singleton<TYPE, ACE_LOCK> *
00117 TAO_TSS_Singleton<TYPE, ACE_LOCK>::singleton_ = 0;
00118 #endif
00119
00120
00121 template <class TYPE, class ACE_LOCK> void
00122 TAO_TSS_Singleton<TYPE, ACE_LOCK>::dump (void)
00123 {
00124 ACE_TRACE ("TAO_TSS_Singleton<TYPE, ACE_LOCK>::dump");
00125
00126 #if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00127 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("instance_ = %x"),
00128 TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ()));
00129 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00130 #endif
00131 }
00132
00133 template <class TYPE, class ACE_LOCK> TAO_TSS_Singleton<TYPE, ACE_LOCK> *&
00134 TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance_i (void)
00135 {
00136 #if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
00137
00138
00139 static TAO_TSS_Singleton<TYPE, ACE_LOCK> *singleton_ = 0;
00140
00141 return singleton_;
00142 #else
00143 return TAO_TSS_Singleton<TYPE, ACE_LOCK>::singleton_;
00144 #endif
00145 }
00146
00147 template <class TYPE, class ACE_LOCK> TYPE *
00148 TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance (void)
00149 {
00150 ACE_TRACE ("TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance");
00151
00152 TAO_TSS_Singleton<TYPE, ACE_LOCK> *&singleton =
00153 TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance_i ();
00154
00155
00156 if (singleton == 0)
00157 {
00158 if (TAO_Singleton_Manager::starting_up () ||
00159 TAO_Singleton_Manager::shutting_down ())
00160 {
00161
00162
00163
00164
00165
00166
00167
00168 ACE_NEW_RETURN (singleton, (TAO_TSS_Singleton<TYPE, ACE_LOCK>), 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
00183 if (singleton == 0)
00184 {
00185 #endif
00186 ACE_NEW_RETURN (singleton, (TAO_TSS_Singleton<TYPE, ACE_LOCK>),
00187 0);
00188
00189
00190 TAO_Singleton_Manager::at_exit (singleton);
00191 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
00192 }
00193 #endif
00194 }
00195 }
00196
00197 return ACE_TSS_GET (&singleton->instance_, TYPE);
00198 }
00199
00200 template <class TYPE, class ACE_LOCK> void
00201 TAO_TSS_Singleton<TYPE, ACE_LOCK>::cleanup (void *)
00202 {
00203 delete this;
00204 TAO_TSS_Singleton<TYPE, ACE_LOCK>::instance_i () = 0;
00205 }
00206
00207 TAO_END_VERSIONED_NAMESPACE_DECL
00208
00209 #endif