summaryrefslogtreecommitdiff
path: root/TAO/tao/TAO_Singleton_Manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/tao/TAO_Singleton_Manager.cpp')
-rw-r--r--TAO/tao/TAO_Singleton_Manager.cpp95
1 files changed, 33 insertions, 62 deletions
diff --git a/TAO/tao/TAO_Singleton_Manager.cpp b/TAO/tao/TAO_Singleton_Manager.cpp
index 829f808c51f..fcacaa78283 100644
--- a/TAO/tao/TAO_Singleton_Manager.cpp
+++ b/TAO/tao/TAO_Singleton_Manager.cpp
@@ -28,44 +28,19 @@ ACE_RCSID (tao,
TAO_Singleton_Manager,
"$Id$")
-
-namespace
-{
- // Singleton instance pointer.
- TAO_Singleton_Manager * the_instance = 0;
-}
-
-#if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
- && ACE_HAS_VERSIONED_NAMESPACE == 1) \
- && !(defined (_MSC_VER) && _MSC_VER <= 1200)
-// MSVC++ 6's preprocessor can't handle macro expansions required by
-// the versioned namespace support. *sigh*
-
-# define TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME ACE_PREPROC_CONCATENATE(TAO_VERSIONED_NAMESPACE_NAME, _TAO_Singleton_Manager_cleanup_destroyer)
-
-#else
-
-# define TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME TAO_Singleton_Manager_cleanup_destroyer
-
-#endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
-
-// Adapter for cleanup, used to register cleanup function with the
-// ACE_Object_Manager.
extern "C" void
-TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME (void *, void *)
+TAO_Singleton_Manager_cleanup_destroyer (void *, void *)
{
-#if defined (TAO_HAS_VERSIONED_NAMESPACE) \
- && TAO_HAS_VERSIONED_NAMESPACE == 1
- using namespace TAO_VERSIONED_NAMESPACE_NAME;
-#endif /* TAO_HAS_VERSIONED_NAMESPACE */
-
- if (the_instance)
+ if (TAO_Singleton_Manager::instance_)
{
(void) TAO_Singleton_Manager::instance ()->fini ();
}
}
-TAO_BEGIN_VERSIONED_NAMESPACE_DECL
+TAO_Singleton_Manager *TAO_Singleton_Manager::instance_ = 0;
+
+void *TAO_Singleton_Manager::preallocated_object[
+ TAO_Singleton_Manager::TAO_PREALLOCATED_OBJECTS] = { 0 };
TAO_Singleton_Manager::TAO_Singleton_Manager (void)
// default_mask_ isn't initialized, because it's defined by <init>.
@@ -80,9 +55,9 @@ TAO_Singleton_Manager::TAO_Singleton_Manager (void)
#endif /* ACE_HAS_EXCEPTIONS */
{
// Be sure that no further instances are created via instance ().
- if (the_instance == 0)
+ if (instance_ == 0)
{
- the_instance = this;
+ instance_ = this;
}
// @@ This is a hack. Allow the TAO_Singleton_Manager to be registered
@@ -127,14 +102,14 @@ TAO_Singleton_Manager::instance (void)
// instances, or before any other threads have been created in the
// process. So, it's not thread safe.
- if (the_instance == 0)
+ if (instance_ == 0)
{
TAO_Singleton_Manager *instance_pointer;
ACE_NEW_RETURN (instance_pointer,
TAO_Singleton_Manager,
0);
- ACE_ASSERT (instance_pointer == the_instance);
+ ACE_ASSERT (instance_pointer == instance_);
instance_pointer->dynamically_allocated_ = 1;
@@ -142,7 +117,7 @@ TAO_Singleton_Manager::instance (void)
}
else
{
- return the_instance;
+ return instance_;
}
}
@@ -170,7 +145,7 @@ TAO_Singleton_Manager::init (int register_with_object_manager)
// initialized.
this->object_manager_state_ = OBJ_MAN_INITIALIZING;
- if (this == the_instance)
+ if (this == instance_)
{
# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
// @@ No MT-specific pre-allocated objects.
@@ -210,7 +185,7 @@ TAO_Singleton_Manager::init (int register_with_object_manager)
if (register_with_object_manager == 1
&& ACE_Object_Manager::at_exit (
this,
- (ACE_CLEANUP_FUNC) TAO_SINGLETON_MANAGER_CLEANUP_DESTROYER_NAME,
+ (ACE_CLEANUP_FUNC) TAO_Singleton_Manager_cleanup_destroyer,
0) != 0)
return -1;
@@ -230,7 +205,7 @@ TAO_Singleton_Manager::init (int register_with_object_manager)
int
TAO_Singleton_Manager::fini (void)
{
- if (the_instance == 0 || this->shutting_down_i ())
+ if (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;
@@ -254,18 +229,18 @@ TAO_Singleton_Manager::fini (void)
// registration.
this->exit_info_.call_hooks ();
-// // Only clean up preallocated objects when the singleton Instance is being
-// // destroyed.
-// if (this == the_instance)
-// {
-// #if ! defined (ACE_HAS_STATIC_PREALLOCATION)
-// // Cleanup the dynamically preallocated objects.
-// # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
-// // @@ No MT-specific preallocated objects yet.
-// # endif /* ACE_MT_SAFE */
-// // @@ No preallocated objects yet.
-// #endif /* ! ACE_HAS_STATIC_PREALLOCATION */
-// }
+ // Only clean up preallocated objects when the singleton Instance is being
+ // destroyed.
+ if (this == instance_)
+ {
+#if ! defined (ACE_HAS_STATIC_PREALLOCATION)
+ // Cleanup the dynamically preallocated objects.
+# if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0)
+ // @@ No MT-specific preallocated objects yet.
+# endif /* ACE_MT_SAFE */
+ // @@ No preallocated objects yet.
+#endif /* ! ACE_HAS_STATIC_PREALLOCATION */
+ }
delete this-> default_mask_;
this->default_mask_ = 0;
@@ -291,8 +266,8 @@ TAO_Singleton_Manager::fini (void)
// 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 == instance_)
+ instance_ = 0;
if (this->dynamically_allocated_)
{
@@ -305,18 +280,16 @@ TAO_Singleton_Manager::fini (void)
int
TAO_Singleton_Manager::starting_up (void)
{
- return
- the_instance
- ? the_instance->starting_up_i ()
+ return TAO_Singleton_Manager::instance_
+ ? instance_->starting_up_i ()
: 1;
}
int
TAO_Singleton_Manager::shutting_down (void)
{
- return
- the_instance
- ? the_instance->shutting_down_i ()
+ return TAO_Singleton_Manager::instance_
+ ? instance_->shutting_down_i ()
: 1;
}
@@ -347,7 +320,7 @@ TAO_Singleton_Manager::at_exit_i (void *object,
{
ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_RECURSIVE_MUTEX,
ace_mon,
- *the_instance->internal_lock_,
+ *instance_->internal_lock_,
-1));
if (this->shutting_down_i ())
@@ -365,5 +338,3 @@ TAO_Singleton_Manager::at_exit_i (void *object,
return this->exit_info_.at_exit_i (object, cleanup_hook, param);
}
-
-TAO_END_VERSIONED_NAMESPACE_DECL