#include <TAO_Singleton_Manager.h>
Inheritance diagram for TAO_Singleton_Manager:
Public Member Functions | |
virtual int | init (void) |
Explicitly initialize. | |
int | init (int register_with_object_manager) |
virtual int | fini (void) |
Explicitly destroy. | |
Static Public Member Functions | |
int | starting_up (void) |
int | shutting_down (void) |
sigset_t * | default_mask (void) |
ACE_Thread_Hook * | thread_hook (void) |
Returns the current thread hook for the process. | |
ACE_Thread_Hook * | thread_hook (ACE_Thread_Hook *new_thread_hook) |
Returns the existing thread hook and assign a new_thread_hook. | |
TAO_Singleton_Manager * | instance (void) |
Accessor to singleton instance. | |
int | at_exit (ACE_Cleanup *object, void *param=0) |
int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
Protected Member Functions | |
TAO_Singleton_Manager (void) | |
~TAO_Singleton_Manager (void) | |
Private Member Functions | |
int | at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param) |
TAO_Singleton_Manager (const TAO_Singleton_Manager &) | |
TAO_Singleton_Manager & | operator= (const TAO_Singleton_Manager &) |
Private Attributes | |
sigset_t * | default_mask_ |
Default signal set used, for example, in ACE_Sig_Guard. | |
ACE_Thread_Hook * | thread_hook_ |
Thread hook that's used by this process. | |
ACE_OS_Exit_Info | exit_info_ |
For at_exit support. | |
int | registered_with_object_manager_ |
The TAO_Singleton_Manager is basically simplified version of the ACE_Object_Manager. It is designed specifically to manage singletons created by TAO. For example, singleton instances created by TAO will be automatically registered with the singleton instance of this Singleton Manager.
Definition at line 50 of file TAO_Singleton_Manager.h.
|
|
|
Definition at line 73 of file TAO_Singleton_Manager.cpp. References fini().
00074 { 00075 this->dynamically_allocated_ = 0; // Don't delete this again in fini() 00076 (void) this->fini (); 00077 } |
|
|
|
cleanup_hook points to a (global, or static member) function that is called for the object or array when it to be destroyed. It may perform any necessary cleanup specific for that object or its class. param is passed as the second parameter to the cleanup_hook function; the first parameter is the object (or array) to be destroyed. cleanup_hook, for example, may delete the object (or array). For OS's that do not have processes, this function is the same as . Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered. Definition at line 20 of file TAO_Singleton_Manager.inl. References at_exit_i(), and instance().
00023 { 00024 return TAO_Singleton_Manager::instance ()->at_exit_i ( 00025 object, 00026 cleanup_hook, 00027 param); 00028 } |
|
The object is deleted via the ace_cleanup_destroyer. If you need more flexiblity, see the other at_exit method below. For OS's that do not have processes, cleanup takes place at the end of main. Returns 0 on success. On failure, returns -1 and sets errno to: EAGAIN if shutting down, ENOMEM if insufficient virtual memory, or EEXIST if the object (or array) had already been registered. Definition at line 9 of file TAO_Singleton_Manager.inl. References ACE_CLEANUP_DESTROYER_NAME(), ACE_CLEANUP_FUNC, at_exit_i(), and instance(). Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00011 { 00012 return TAO_Singleton_Manager::instance ()->at_exit_i ( 00013 object, 00014 (ACE_CLEANUP_FUNC) ACE_CLEANUP_DESTROYER_NAME, 00015 param); 00016 } |
|
Register an object or array for deletion at program termination. See description of static version above for return values. Definition at line 288 of file TAO_Singleton_Manager.cpp. References ACE_GUARD_RETURN, ACE_OS_Exit_Info::at_exit_i(), ACE_OS_Exit_Info::find(), ACE_Object_Manager_Base::shutting_down_i(), TAO_SYNCH_RECURSIVE_MUTEX, and the_instance. Referenced by at_exit().
00291 { 00292 ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, 00293 ace_mon, 00294 *the_instance->internal_lock_, 00295 -1)); 00296 00297 if (this->shutting_down_i ()) 00298 { 00299 errno = EAGAIN; 00300 return -1; 00301 } 00302 00303 if (this->exit_info_.find (object)) 00304 { 00305 // The object has already been registered. 00306 errno = EEXIST; 00307 return -1; 00308 } 00309 00310 return this->exit_info_.at_exit_i (object, cleanup_hook, param); 00311 } |
|
Accesses a default signal set used, for example, in ACE_Sig_Guard methods. Definition at line 80 of file TAO_Singleton_Manager.cpp. References default_mask_, and instance().
00081 { 00082 return TAO_Singleton_Manager::instance ()->default_mask_; 00083 } |
|
Explicitly destroy.
Implements ACE_Object_Manager_Base. Definition at line 208 of file TAO_Singleton_Manager.cpp. References ACE_OS_Exit_Info::call_hooks(), ACE_Object_Manager_Base::fini(), ACE_Object_Manager_Base::shutting_down_i(), and the_instance. Referenced by ~TAO_Singleton_Manager().
00209 { 00210 if (the_instance == 0 || this->shutting_down_i ()) 00211 // Too late. Or, maybe too early. Either fini () has already 00212 // been called, or init () was never called. 00213 return this->object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1; 00214 00215 // No mutex here. Only the main thread should destroy the singleton 00216 // TAO_Singleton_Manager instance. 00217 00218 // Indicate that the TAO_Singleton_Manager instance is being shut 00219 // down. This object manager should be the last one to be shut 00220 // down. 00221 this->object_manager_state_ = OBJ_MAN_SHUTTING_DOWN; 00222 00223 // If another Object_Manager has registered for termination, do it. 00224 if (this->next_) 00225 { 00226 this->next_->fini (); 00227 this->next_ = 0; // Protect against recursive calls. 00228 } 00229 00230 // Call all registered cleanup hooks, in reverse order of 00231 // registration. 00232 this->exit_info_.call_hooks (); 00233 00234 // // Only clean up preallocated objects when the singleton Instance is being 00235 // // destroyed. 00236 // if (this == the_instance) 00237 // { 00238 // #if ! defined (ACE_HAS_STATIC_PREALLOCATION) 00239 // // Cleanup the dynamically preallocated objects. 00240 // # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00241 // // @@ No MT-specific preallocated objects yet. 00242 // # endif /* ACE_MT_SAFE */ 00243 // // @@ No preallocated objects yet. 00244 // #endif /* ! ACE_HAS_STATIC_PREALLOCATION */ 00245 // } 00246 00247 delete this-> default_mask_; 00248 this->default_mask_ = 0; 00249 00250 #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00251 delete this->internal_lock_; 00252 this->internal_lock_ = 0; 00253 #endif /* ACE_MT_SAFE */ 00254 00255 // Indicate that this TAO_Singleton_Manager instance has been shut down. 00256 this->object_manager_state_ = OBJ_MAN_SHUT_DOWN; 00257 00258 if (this == the_instance) 00259 the_instance = 0; 00260 00261 if (this->dynamically_allocated_) 00262 { 00263 delete this; 00264 } 00265 00266 return 0; 00267 } |
|
Explicitly initialize the TAO_Singleton_Manager, in addition to explicitly registering (or not registering) with the ACE_Object_Manager. Definition at line 142 of file TAO_Singleton_Manager.cpp. References ACE_CLEANUP_FUNC, ACE_NEW_RETURN, ACE_Object_Manager::at_exit(), registered_with_object_manager_, ACE_OS::sigfillset(), ACE_Object_Manager_Base::starting_up_i(), and the_instance.
00143 { 00144 if (this->starting_up_i ()) 00145 { 00146 // First, indicate that this TAO_Singleton_Manager instance is being 00147 // initialized. 00148 this->object_manager_state_ = OBJ_MAN_INITIALIZING; 00149 00150 if (this == the_instance) 00151 { 00152 # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) 00153 // @@ No MT-specific pre-allocated objects. 00154 # endif /* ACE_MT_SAFE */ 00155 } 00156 00157 ACE_NEW_RETURN (this->default_mask_, sigset_t, -1); 00158 ACE_OS::sigfillset (this->default_mask_); 00159 00160 // Finally, indicate that the TAO_Singleton_Manager instance has 00161 // been initialized. 00162 this->object_manager_state_ = OBJ_MAN_INITIALIZED; 00163 00164 return 0; 00165 } 00166 00167 // @@ This strange looking code is what provides the "register on 00168 // explicit call to init()" semantics. This was needed since the 00169 // TAO_Singleton_Manager constructor invokes init(). 00170 // Unfortunately, I couldn't get rid of that init() call without 00171 // breaking things. The fact things broke needs to be 00172 // investigated further. 00173 if (this->registered_with_object_manager_ != -1 00174 && register_with_object_manager != this->registered_with_object_manager_) 00175 { 00176 // An attempt was made to register the TAO_Singleton_Manager 00177 // with a manager of a different type from the one it is 00178 // currently registered with. This indicates a problem with the 00179 // caller's logic. 00180 00181 errno = EINVAL; 00182 return -1; 00183 } 00184 00185 if (this->registered_with_object_manager_ == -1) 00186 { 00187 if (register_with_object_manager == 1 00188 && ACE_Object_Manager::at_exit ( 00189 this, 00190 (ACE_CLEANUP_FUNC) TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME, 00191 0) != 0) 00192 return -1; 00193 00194 this->registered_with_object_manager_ = 00195 register_with_object_manager; 00196 } 00197 00198 // Had already initialized. 00199 return 1; 00200 } |
|
Explicitly initialize.
Implements ACE_Object_Manager_Base. Definition at line 127 of file TAO_Singleton_Manager.cpp. References registered_with_object_manager_. Referenced by CORBA::ORB_init(), and PortableInterceptor::register_orb_initializer().
00128 { 00129 if (this->registered_with_object_manager_ == -1) 00130 { 00131 // Register the TAO_Singleton_Manager with the 00132 // ACE_Object_Manager. 00133 int register_with_object_manager = 1; 00134 00135 return this->init (register_with_object_manager); 00136 } 00137 00138 return 1; // Already initialized. 00139 } |
|
Accessor to singleton instance.
Definition at line 101 of file TAO_Singleton_Manager.cpp. References ACE_ASSERT, ACE_NEW_RETURN, ACE_Object_Manager_Base::dynamically_allocated_, and the_instance. Referenced by at_exit(), default_mask(), CORBA::ORB_init(), PortableInterceptor::register_orb_initializer(), and thread_hook().
00102 { 00103 // This function should be called during construction of static 00104 // instances, or before any other threads have been created in the 00105 // process. So, it's not thread safe. 00106 00107 if (the_instance == 0) 00108 { 00109 TAO_Singleton_Manager *instance_pointer = 0; 00110 00111 ACE_NEW_RETURN (instance_pointer, 00112 TAO_Singleton_Manager, 00113 0); 00114 ACE_ASSERT (instance_pointer == the_instance); 00115 00116 instance_pointer->dynamically_allocated_ = 1; 00117 00118 return instance_pointer; 00119 } 00120 else 00121 { 00122 return the_instance; 00123 } 00124 } |
|
|
|
Returns 1 after the TAO_Singleton_Manager has been destroyed. See ACE_Object_Manager::shutting_down for more information. Definition at line 279 of file TAO_Singleton_Manager.cpp. References ACE_Object_Manager_Base::shutting_down_i(), and the_instance. Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00280 { 00281 return 00282 the_instance 00283 ? the_instance->shutting_down_i () 00284 : 1; 00285 } |
|
Returns 1 before the TAO_Singleton_Manager has been constructed. See ACE_Object_Manager::starting_up for more information. Definition at line 270 of file TAO_Singleton_Manager.cpp. References ACE_Object_Manager_Base::starting_up_i(), and the_instance. Referenced by TAO_TSS_Singleton< TYPE, ACE_LOCK >::instance(), and TAO_Singleton< TYPE, ACE_LOCK >::instance().
00271 { 00272 return 00273 the_instance 00274 ? the_instance->starting_up_i () 00275 : 1; 00276 } |
|
Returns the existing thread hook and assign a new_thread_hook.
Definition at line 92 of file TAO_Singleton_Manager.cpp. References instance(), and thread_hook_.
00093 { 00094 TAO_Singleton_Manager *tao_om = TAO_Singleton_Manager::instance (); 00095 ACE_Thread_Hook *old_hook = tao_om->thread_hook_; 00096 tao_om->thread_hook_ = new_thread_hook; 00097 return old_hook; 00098 } |
|
Returns the current thread hook for the process.
Definition at line 86 of file TAO_Singleton_Manager.cpp. References instance(), and thread_hook_.
00087 { 00088 return TAO_Singleton_Manager::instance ()->thread_hook_; 00089 } |
|
Default signal set used, for example, in ACE_Sig_Guard.
Definition at line 144 of file TAO_Singleton_Manager.h. Referenced by default_mask(). |
|
For at_exit support.
Definition at line 150 of file TAO_Singleton_Manager.h. |
|
Indicates if TAO_Singleton_Manager is registered with the ACE_Object_Manager. Definition at line 154 of file TAO_Singleton_Manager.h. Referenced by init(). |
|
Thread hook that's used by this process.
Definition at line 147 of file TAO_Singleton_Manager.h. Referenced by thread_hook(). |