summaryrefslogtreecommitdiff
path: root/ace/Singleton.cpp
diff options
context:
space:
mode:
authorlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-09-22 18:15:37 +0000
committerlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-09-22 18:15:37 +0000
commiteda79b335ab42b4273c2c1f193d66f22d264ba6b (patch)
tree26231935ecf2dbfb6ebb12c6f5b7213710fd2498 /ace/Singleton.cpp
parent2af513c4e333e134946d837933fea066a25a4034 (diff)
downloadATCD-eda79b335ab42b4273c2c1f193d66f22d264ba6b.tar.gz
removed instance (TYPE *) member function because it wasn't being used. And, it allows us to store the contained instances_ as an object instead of a pointer, saving a dynamic memory allocation on construction.
Diffstat (limited to 'ace/Singleton.cpp')
-rw-r--r--ace/Singleton.cpp48
1 files changed, 11 insertions, 37 deletions
diff --git a/ace/Singleton.cpp b/ace/Singleton.cpp
index f1d28f8a4c4..640114918f7 100644
--- a/ace/Singleton.cpp
+++ b/ace/Singleton.cpp
@@ -20,7 +20,7 @@ ACE_Singleton<TYPE, LOCK>::dump (void)
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
ACE_DEBUG ((LM_DEBUG, "instance_ = %x",
- ACE_Singleton<TYPE, LOCK>::instance_i ()));
+ ACE_Singleton<TYPE, LOCK>::instance_i ()));
ACE_Singleton<TYPE, LOCK>::singleton_lock_i ().dump ();
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
@@ -69,40 +69,20 @@ ACE_Singleton<TYPE, LOCK>::instance (void)
if (singleton == 0)
{
- ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, LOCK>), 0);
+ ACE_NEW_RETURN (singleton, (ACE_Singleton<TYPE, LOCK>), 0);
// Register for destruction with ACE_Object_Manager.
ACE_Object_Manager::at_exit (singleton);
}
}
- return singleton->instance_;
-}
-
-template <class TYPE, class LOCK> TYPE *
-ACE_Singleton<TYPE, LOCK>::instance (TYPE *new_instance)
-{
- ACE_TRACE ("ACE_Singleton::set_instance");
-
- ACE_GUARD_RETURN (LOCK, ace_mon, (ACE_Singleton<TYPE, LOCK>::singleton_lock_i ()), 0);
-
- ACE_Singleton<TYPE, LOCK> *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i ();
- TYPE *old_instance = singleton->instance_;
- singleton->instance_ = new_instance;
-
- return old_instance;
+ return &singleton->instance_;
}
template <class TYPE, class LOCK> void
ACE_Singleton<TYPE, LOCK>::cleanup (void *)
{
- if (this->instance_ != 0)
- {
- delete this->instance_;
- this->instance_ = 0;
-
- delete this;
- }
+ delete this;
}
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
@@ -121,7 +101,7 @@ ACE_TSS_Singleton<TYPE, LOCK>::dump (void)
ACE_TRACE ("ACE_TSS_Singleton<TYPE, LOCK>::dump");
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
- ACE_DEBUG ((LM_DEBUG, "instance_ = %x", singleton_->instance_));
+ ACE_DEBUG ((LM_DEBUG, "instance_ = %x", &singleton_->instance_));
ace_singleton_lock_.dump();
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
@@ -147,14 +127,14 @@ ACE_TSS_Singleton<TYPE, LOCK>::instance (void)
ACE_GUARD_RETURN (LOCK, ace_mon, ace_singleton_lock_, 0);
if (singleton_ == 0)
- {
+ {
ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, LOCK>), 0);
#if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */
// Register for destruction with ACE_Object_Manager.
ACE_Object_Manager::at_thread_exit (instance_);
#endif /* 0 */
- }
+ }
}
#else
@@ -165,19 +145,19 @@ ACE_TSS_Singleton<TYPE, LOCK>::instance (void)
ACE_GUARD_RETURN (LOCK, ace_mon, (ACE_TSS_Singleton<TYPE, LOCK>::ace_singleton_lock_), 0);
if (singleton_ == 0)
- {
+ {
ACE_NEW_RETURN (singleton_, (ACE_TSS_Singleton<TYPE, LOCK>), 0);
#if 0 /* ACE_Object_Manager::at_thread_exit () is not implemented yet. */
// Register for destruction with ACE_Object_Manager.
ACE_Object_Manager::at_thread_exit (instance_);
#endif /* 0 */
- }
+ }
}
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
- return ACE_TSS_GET (singleton_->instance_, TYPE);
+ return ACE_TSS_GET (&singleton_->instance_, TYPE);
}
template <class TYPE, class LOCK> void
@@ -185,13 +165,7 @@ ACE_TSS_Singleton<TYPE, LOCK>::cleanup (void *)
{
ACE_TRACE ("ACE_TSS_Singleton::cleanup");
- if (this->instance_ != 0)
- {
- delete this->instance_;
- this->instance_ = 0;
-
- delete this;
- }
+ delete this;
}
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)