summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authornw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-30 09:34:43 +0000
committernw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-30 09:34:43 +0000
commit641d6e2950fac95d8fa66ed4a539ca269ab1c9c4 (patch)
tree01ab7d7d75720ee563e3b4fb23ca3f149353df7f /ace
parentc5f1d38df7072ad65784a17b0e61b65a825efb52 (diff)
downloadATCD-641d6e2950fac95d8fa66ed4a539ca269ab1c9c4.tar.gz
Added class ACE_Static_Object_Lock.
Diffstat (limited to 'ace')
-rw-r--r--ace/Synch.cpp38
-rw-r--r--ace/Synch.h20
2 files changed, 58 insertions, 0 deletions
diff --git a/ace/Synch.cpp b/ace/Synch.cpp
index b04b36ce2bc..42ae8b59ddf 100644
--- a/ace/Synch.cpp
+++ b/ace/Synch.cpp
@@ -13,6 +13,10 @@
#include "ace/Synch.i"
#endif /* __ACE_INLINE__ */
+#if defined (ACE_MT_SAFE) && defined (ACE_HAS_THREADS)
+ACE_Thread_Mutex *ACE_Static_Object_Lock::mutex_ = 0;
+#endif
+
ACE_ALLOC_HOOK_DEFINE(ACE_Null_Mutex)
ACE_ALLOC_HOOK_DEFINE(ACE_File_Lock)
ACE_ALLOC_HOOK_DEFINE(ACE_RW_Process_Mutex)
@@ -905,6 +909,40 @@ ACE_RW_Thread_Mutex::dump (void) const
ACE_RW_Mutex::dump ();
}
+////////////////////////////////////////////////////////////////
+#include "ace/Malloc.h"
+
+#if defined (ACE_HAS_SIG_C_FUNC)
+extern "C" static void
+ace_static_object_lock_atexit (void)
+{
+ ACE_Static_Object_Lock::atexit ();
+}
+#endif /* ACE_HAS_SIG_C_FUNC */
+
+void
+ACE_Static_Object_Lock::atexit (void)
+{
+ ACE_Allocator::close_singleton ();
+ delete ACE_Static_Object_Lock::mutex_;
+}
+
+ACE_Thread_Mutex *
+ACE_Static_Object_Lock::get_lock (void)
+{
+ // We assume things before main are single threaded.
+ if (ACE_Static_Object_Lock::mutex_ == 0)
+ {
+ ACE_NEW_RETURN (ACE_Static_Object_Lock::mutex_, ACE_Thread_Mutex, 0);
+#if defined (ACE_HAS_SIG_C_FUNC)
+ ::atexit (ace_static_object_lock_atexit);
+#else
+ ::atexit (ACE_Static_Object_Lock::atexit);
+#endif
+ }
+ return ACE_Static_Object_Lock::mutex_;
+}
+
#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION)
// These are only specialized with ACE_HAS_THREADS.
template class ACE_Guard<ACE_SYNCH_RW_MUTEX>;
diff --git a/ace/Synch.h b/ace/Synch.h
index 02153957d6a..2db05eefed4 100644
--- a/ace/Synch.h
+++ b/ace/Synch.h
@@ -1216,6 +1216,26 @@ public:
// Declare the dynamic allocation hooks.
};
+class ACE_Export ACE_Static_Object_Lock
+ // = TITLE
+ // Provide an interface to access a global lock.
+ //
+ // = DESCRIPTION
+ // This class is used to serialize the creation of
+ // static singleton objects.
+{
+public:
+ static ACE_Thread_Mutex *get_lock (void);
+ // static lock access point
+
+ static void atexit (void);
+ // clean things up when program exit
+
+private:
+ static ACE_Thread_Mutex *mutex_;
+ // pointer to actual lock
+};
+
#endif /* ACE_HAS_THREADS */
#if defined (__ACE_INLINE__)