Manager for TAO library services and singleton cleanup. More...
#include <TAO_Singleton_Manager.h>
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 | |
static int | starting_up (void) |
static int | shutting_down (void) |
static sigset_t * | default_mask (void) |
static ACE_Thread_Hook * | thread_hook (void) |
Returns the current thread hook for the process. | |
static ACE_Thread_Hook * | thread_hook (ACE_Thread_Hook *new_thread_hook) |
Returns the existing thread hook and assign a new_thread_hook. | |
static TAO_Singleton_Manager * | instance (void) |
Accessor to singleton instance. | |
static int | at_exit (ACE_Cleanup *object, void *param=0, const char *name=0) |
static int | at_exit (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char *name) |
Protected Member Functions | |
TAO_Singleton_Manager (void) | |
Force allocation on the heap. | |
~TAO_Singleton_Manager (void) | |
Force allocation on the heap. | |
Private Member Functions | |
int | at_exit_i (void *object, ACE_CLEANUP_FUNC cleanup_hook, void *param, const char *name) |
TAO_Singleton_Manager (const TAO_Singleton_Manager &) | |
Disallow copying by not implementing the following ... | |
TAO_Singleton_Manager & | operator= (const TAO_Singleton_Manager &) |
Disallow copying by not implementing the following ... | |
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_ |
Manager for TAO library services and singleton cleanup.
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 49 of file TAO_Singleton_Manager.h.
TAO_Singleton_Manager::TAO_Singleton_Manager | ( | void | ) | [protected] |
Force allocation on the heap.
Definition at line 64 of file TAO_Singleton_Manager.cpp.
: default_mask_ (0), thread_hook_ (0), exit_info_ (), registered_with_object_manager_ (-1) #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) , internal_lock_ (0) # endif /* ACE_MT_SAFE */ { #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) ACE_NEW (this->internal_lock_, TAO_SYNCH_RECURSIVE_MUTEX); # endif /* ACE_MT_SAFE */ // Be sure that no further instances are created via instance (). if (the_instance == 0) { the_instance = this; } // @@ This is a hack. Allow the TAO_Singleton_Manager to be registered // with the ACE_Object_Manager (or not) in an explicit call to // TAO_Singleton_Manager::init(). However, once the explicit call is // made, it will not be possible to alter the setting. int register_with_object_manager = -1; (void) this->init (register_with_object_manager); }
TAO_Singleton_Manager::~TAO_Singleton_Manager | ( | void | ) | [protected] |
Force allocation on the heap.
Definition at line 91 of file TAO_Singleton_Manager.cpp.
{ this->dynamically_allocated_ = false; // Don't delete this again in fini() (void) this->fini (); #if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) delete this->internal_lock_; this->internal_lock_ = 0; #endif /* ACE_MT_SAFE */ }
TAO_Singleton_Manager::TAO_Singleton_Manager | ( | const TAO_Singleton_Manager & | ) | [private] |
Disallow copying by not implementing the following ...
int TAO_Singleton_Manager::at_exit | ( | ACE_Cleanup * | object, | |
void * | param = 0 , |
|||
const char * | name = 0 | |||
) | [static] |
Register an ACE_Cleanup object for cleanup at process termination. 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.
{ return TAO_Singleton_Manager::instance ()->at_exit_i ( object, (ACE_CLEANUP_FUNC) ACE_CLEANUP_DESTROYER_NAME, param, name); }
int TAO_Singleton_Manager::at_exit | ( | void * | object, | |
ACE_CLEANUP_FUNC | cleanup_hook, | |||
void * | param, | |||
const char * | name | |||
) | [static] |
Register an object (or array) for cleanup at process termination. 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 at_thread_exit
. 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 22 of file TAO_Singleton_Manager.inl.
{ return TAO_Singleton_Manager::instance ()->at_exit_i ( object, cleanup_hook, param, name); }
int TAO_Singleton_Manager::at_exit_i | ( | void * | object, | |
ACE_CLEANUP_FUNC | cleanup_hook, | |||
void * | param, | |||
const char * | name | |||
) | [private] |
Register an object or array for deletion at program termination. See description of static version above for return values.
Definition at line 298 of file TAO_Singleton_Manager.cpp.
{ ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX, ace_mon, *the_instance->internal_lock_, -1)); if (this->shutting_down_i ()) { errno = EAGAIN; return -1; } if (this->exit_info_.find (object)) { // The object has already been registered. errno = EEXIST; return -1; } return this->exit_info_.at_exit_i (object, cleanup_hook, param, name); }
sigset_t * TAO_Singleton_Manager::default_mask | ( | void | ) | [static] |
Accesses a default signal set used, for example, in ACE_Sig_Guard methods.
Definition at line 103 of file TAO_Singleton_Manager.cpp.
{ return TAO_Singleton_Manager::instance ()->default_mask_; }
int TAO_Singleton_Manager::fini | ( | void | ) | [virtual] |
Explicitly destroy.
Implements ACE_Object_Manager_Base.
Definition at line 228 of file TAO_Singleton_Manager.cpp.
{ if (the_instance == 0 || this->shutting_down_i ()) { // Too late. Or, maybe too early. Either fini () has already // been called, or init () was never called. return this->object_manager_state_ == OBJ_MAN_SHUT_DOWN ? 1 : -1; } // No mutex here. Only the main thread should destroy the singleton // TAO_Singleton_Manager instance. // Indicate that the TAO_Singleton_Manager instance is being shut // down. This object manager should be the last one to be shut // down. this->object_manager_state_ = OBJ_MAN_SHUTTING_DOWN; // If another Object_Manager has registered for termination, do it. if (this->next_) { this->next_->fini (); this->next_ = 0; // Protect against recursive calls. } // Call all registered cleanup hooks, in reverse order of // registration. this->exit_info_.call_hooks (); // Remove ourselves from the ACE object manager if (this->registered_with_object_manager_ == 1) { ACE_Object_Manager::remove_at_exit (this); } delete this->default_mask_; this->default_mask_ = 0; // Indicate that this TAO_Singleton_Manager instance has been shut down. this->object_manager_state_ = OBJ_MAN_SHUT_DOWN; if (this == the_instance) the_instance = 0; if (this->dynamically_allocated_) { delete this; } return 0; }
int TAO_Singleton_Manager::init | ( | int | register_with_object_manager | ) |
Explicitly initialize the TAO_Singleton_Manager, in addition to explicitly registering (or not registering) with the ACE_Object_Manager.
Definition at line 164 of file TAO_Singleton_Manager.cpp.
{ if (this->starting_up_i ()) { // First, indicate that this TAO_Singleton_Manager instance is being // initialized. this->object_manager_state_ = OBJ_MAN_INITIALIZING; if (this == the_instance) { # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) // @@ No MT-specific pre-allocated objects. # endif /* ACE_MT_SAFE */ } ACE_NEW_RETURN (this->default_mask_, sigset_t, -1); ACE_OS::sigfillset (this->default_mask_); // Finally, indicate that the TAO_Singleton_Manager instance has // been initialized. this->object_manager_state_ = OBJ_MAN_INITIALIZED; return 0; } // @@ This strange looking code is what provides the "register on // explicit call to init()" semantics. This was needed since the // TAO_Singleton_Manager constructor invokes init(). // Unfortunately, I couldn't get rid of that init() call without // breaking things. The fact things broke needs to be // investigated further. if (this->registered_with_object_manager_ != -1 && register_with_object_manager != this->registered_with_object_manager_) { // An attempt was made to register the TAO_Singleton_Manager // with a manager of a different type from the one it is // currently registered with. This indicates a problem with the // caller's logic. errno = EINVAL; return -1; } if (this->registered_with_object_manager_ == -1) { if (register_with_object_manager == 1 && ACE_Object_Manager::at_exit ( this, (ACE_CLEANUP_FUNC) TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME, 0, typeid (*this).name ()) != 0) return -1; this->registered_with_object_manager_ = register_with_object_manager; } // Had already initialized. return 1; }
int TAO_Singleton_Manager::init | ( | void | ) | [virtual] |
Explicitly initialize.
Implements ACE_Object_Manager_Base.
Definition at line 149 of file TAO_Singleton_Manager.cpp.
{ if (this->registered_with_object_manager_ == -1) { // Register the TAO_Singleton_Manager with the // ACE_Object_Manager. int const register_with_object_manager = 1; return this->init (register_with_object_manager); } return 1; // Already initialized. }
TAO_Singleton_Manager * TAO_Singleton_Manager::instance | ( | void | ) | [static] |
Accessor to singleton instance.
Definition at line 124 of file TAO_Singleton_Manager.cpp.
{ // This function should be called during construction of static // instances, or before any other threads have been created in the // process. So, it's not thread safe. if (the_instance == 0) { TAO_Singleton_Manager *instance_pointer = 0; ACE_NEW_RETURN (instance_pointer, TAO_Singleton_Manager, 0); ACE_ASSERT (instance_pointer == the_instance); instance_pointer->dynamically_allocated_ = true; return instance_pointer; } else { return the_instance; } }
TAO_Singleton_Manager& TAO_Singleton_Manager::operator= | ( | const TAO_Singleton_Manager & | ) | [private] |
Disallow copying by not implementing the following ...
int TAO_Singleton_Manager::shutting_down | ( | void | ) | [static] |
Returns 1 after the TAO_Singleton_Manager has been destroyed. See ACE_Object_Manager::shutting_down for more information.
Definition at line 289 of file TAO_Singleton_Manager.cpp.
{
return
the_instance
? the_instance->shutting_down_i ()
: 1;
}
int TAO_Singleton_Manager::starting_up | ( | void | ) | [static] |
Returns 1 before the TAO_Singleton_Manager has been constructed. See ACE_Object_Manager::starting_up for more information.
Definition at line 280 of file TAO_Singleton_Manager.cpp.
{
return
the_instance
? the_instance->starting_up_i ()
: 1;
}
ACE_Thread_Hook * TAO_Singleton_Manager::thread_hook | ( | void | ) | [static] |
Returns the current thread hook for the process.
Definition at line 109 of file TAO_Singleton_Manager.cpp.
{ return TAO_Singleton_Manager::instance ()->thread_hook_; }
ACE_Thread_Hook * TAO_Singleton_Manager::thread_hook | ( | ACE_Thread_Hook * | new_thread_hook | ) | [static] |
Returns the existing thread hook and assign a new_thread_hook.
Definition at line 115 of file TAO_Singleton_Manager.cpp.
{ TAO_Singleton_Manager *tao_om = TAO_Singleton_Manager::instance (); ACE_Thread_Hook *old_hook = tao_om->thread_hook_; tao_om->thread_hook_ = new_thread_hook; return old_hook; }
sigset_t* TAO_Singleton_Manager::default_mask_ [private] |
Default signal set used, for example, in ACE_Sig_Guard.
Definition at line 143 of file TAO_Singleton_Manager.h.
For at_exit support.
Definition at line 149 of file TAO_Singleton_Manager.h.
int TAO_Singleton_Manager::registered_with_object_manager_ [private] |
Indicates if TAO_Singleton_Manager is registered with the ACE_Object_Manager.
Definition at line 153 of file TAO_Singleton_Manager.h.
Thread hook that's used by this process.
Definition at line 146 of file TAO_Singleton_Manager.h.