summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-05-14 22:48:54 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-05-14 22:48:54 +0000
commit7f112ff6968e4fee2a38bcca1a6c1f6630d75e37 (patch)
tree78778590b5c6c5e56fd628273ce5a8d6130d6ac1 /ace
parentec23ba492313939a7bc4c3482c7bdccb7cecb9ea (diff)
downloadATCD-7f112ff6968e4fee2a38bcca1a6c1f6630d75e37.tar.gz
*** empty log message ***
Diffstat (limited to 'ace')
-rw-r--r--ace/OS.h9
-rw-r--r--ace/OS.i3
-rw-r--r--ace/Singleton.cpp138
-rw-r--r--ace/Singleton.h45
-rw-r--r--ace/config-aix-4.1.x.h2
-rw-r--r--ace/config-aix-4.2.x.h2
6 files changed, 176 insertions, 23 deletions
diff --git a/ace/OS.h b/ace/OS.h
index 4f049d3163f..68d37bdb6e1 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -2552,6 +2552,15 @@ struct ACE_Export ACE_Str_Buf : public strbuf
// Constructor.
};
+enum ACE_Singleton_Strategy
+ // = TITLE
+ // Select whether the <ACE_Singleton> creates the Singleton on
+ // the heap or in thread-specific storage.
+{
+ ACE_SINGLETON_HEAP,
+ ACE_SINGLETON_TSS
+};
+
class ACE_Export ACE_OS
// = TITLE
// This class defines an operating system independent
diff --git a/ace/OS.i b/ace/OS.i
index f96744f06a4..af8f5ce2d1a 100644
--- a/ace/OS.i
+++ b/ace/OS.i
@@ -4074,6 +4074,9 @@ ACE_OS::thr_sigsetmask (int how,
ACE_UNUSED_ARG (how);
ACE_NOTSUP_RETURN (-1);
+#elif defined (ACE_HAS_SIGTHREADMASK)
+ ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::sigthreadmask (how, nsm, osm),
+ ace_result_), int, -1);
#elif defined (ACE_HAS_STHREADS)
ACE_OSCALL_RETURN (ACE_ADAPT_RETVAL (::thr_sigsetmask (how, nsm, osm),
ace_result_),
diff --git a/ace/Singleton.cpp b/ace/Singleton.cpp
index 6fae41f308e..54b117dcf4f 100644
--- a/ace/Singleton.cpp
+++ b/ace/Singleton.cpp
@@ -18,49 +18,72 @@ ACE_Singleton<TYPE, LOCK>::dump (void)
ACE_TRACE ("ACE_Singleton<TYPE, LOCK>::dump");
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
- ACE_DEBUG ((LM_DEBUG, "instance_ = %x", instance_));
- ace_singleton_lock_.dump ();
+ ACE_DEBUG ((LM_DEBUG, "instance_ = %x",
+ 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 */
}
-template <class TYPE, class LOCK> TYPE *
-ACE_Singleton<TYPE, LOCK>::instance (void)
+template <class TYPE, class LOCK> TYPE *&
+ACE_Singleton<TYPE, LOCK>::instance_i (void)
{
- ACE_TRACE ("ACE_Singleton::instance");
-
#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Pointer to the Singleton instance. This works around a bug with
// G++...
static TYPE *instance_ = 0;
+ return instance_;
+#else
+ return ACE_Singleton<TYPE, LOCK>::instance_;
+#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+}
+
+template <class TYPE, class LOCK> LOCK &
+ACE_Singleton<TYPE, LOCK>::singleton_lock_i (void)
+{
+#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
// Lock the creation of the singleton. This works around a
// "feature" of G++... ;-)
static LOCK ace_singleton_lock_;
- // Perform the Double-Check pattern...
- if (instance_ == 0)
- {
- ACE_GUARD_RETURN (LOCK, ace_mon, ace_singleton_lock_, 0);
-
- if (instance_ == 0)
- ACE_NEW_RETURN (instance_, TYPE, 0);
- }
- return instance_;
+ return ace_singleton_lock_;
#else
+ return ACE_Singleton<TYPE, LOCK>::ace_singleton_lock_;
+#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+}
+
+template <class TYPE, class LOCK> TYPE *
+ACE_Singleton<TYPE, LOCK>::instance (void)
+{
+ ACE_TRACE ("ACE_Singleton<TYPE, LOCK>::instance");
+
+ TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i ();
// Perform the Double-Check pattern...
- if (ACE_Singleton<TYPE, LOCK>::instance_ == 0)
+ if (singleton == 0)
{
- ACE_GUARD_RETURN (LOCK, ace_mon, (ACE_Singleton<TYPE, LOCK>::ace_singleton_lock_), 0);
+ ACE_GUARD_RETURN (LOCK, ace_mon, ACE_Singleton<TYPE, LOCK>::singleton_lock_i (), 0);
- if (ACE_Singleton<TYPE, LOCK>::instance_ == 0)
- ACE_NEW_RETURN ((ACE_Singleton<TYPE, LOCK>::instance_), TYPE, 0);
+ if (singleton == 0)
+ ACE_NEW_RETURN (singleton, TYPE, 0);
}
- return ACE_Singleton<TYPE, LOCK>::instance_;
+ return singleton;
+}
-#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+template <class TYPE, class LOCK> TYPE *
+ACE_Singleton<TYPE, LOCK>::instance (TYPE *new_instance)
+{
+ ACE_TRACE ("ACE_Singleton::set_instance");
+
+ TYPE *&singleton = ACE_Singleton<TYPE, LOCK>::instance_i ();
+ ACE_GUARD_RETURN (LOCK, ace_mon, ACE_Singleton<TYPE, LOCK>::singleton_lock_i (), 0);
+
+ TYPE *old_instance = singleton;
+ singleton = new_instance;
+
+ return singleton;
}
#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
@@ -73,4 +96,77 @@ template <class TYPE, class LOCK> LOCK
ACE_Singleton<TYPE, LOCK>::ace_singleton_lock_;
#endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> void
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::dump (void)
+{
+ ACE_TRACE ("ACE_SingletonEx<TYPE, LOCK, MEMORY>::dump");
+
+#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
+ ACE_DEBUG ((LM_DEBUG, "instance_ = %x",
+ 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 */
+}
+
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *&
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_i (void)
+{
+#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
+ // Pointer to the Singleton instance. This works around a bug with
+ // G++...
+ static TYPE *instance_ = 0;
+
+ return instance_;
+#else
+ return ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_;
+#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+}
+
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> LOCK &
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::singleton_lock_i (void)
+{
+#if defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
+ // Lock the creation of the singleton. This works around a
+ // "feature" of G++... ;-)
+ static LOCK ace_singletonex_lock_;
+
+ return ace_singletonex_lock_;
+#else
+ return ACE_SingletonEx<TYPE, LOCK, MEMORY>::ace_singletonex_lock_;
+#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+}
+
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance (void)
+{
+ ACE_TRACE ("ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance");
+
+ TYPE *&singleton = ACE_SingletonEx<TYPE, LOCK>::instance_i ();
+
+ // Perform the Double-Check pattern...
+ if (singleton == 0)
+ {
+ ACE_GUARD_RETURN (LOCK, ace_mon, ACE_SingletonEx<TYPE, LOCK>::singleton_lock_i (), 0);
+
+ if (singleton == 0)
+ ACE_NEW_RETURN (singleton, TYPE, 0);
+ }
+
+ if (MEMORY == ACE_SINGLETON_HEAP)
+ return singleton;
+ else
+ return ACE_TSS_GET (singleton, TYPE);
+}
+
+#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
+// Pointer to the Singleton instance.
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> TYPE *
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::instance_ = 0;
+
+// Lock the creation of the singleton.
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY> LOCK
+ACE_SingletonEx<TYPE, LOCK, MEMORY>::ace_singletonex_lock_;
+#endif /* !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES) */
+
#endif /* ACE_SINGLETON_C */
diff --git a/ace/Singleton.h b/ace/Singleton.h
index 86966d9f0bb..f2bcdde8c3d 100644
--- a/ace/Singleton.h
+++ b/ace/Singleton.h
@@ -34,6 +34,9 @@ public:
static TYPE *instance (void);
// Global access point to the Singleton.
+ static TYPE *instance (TYPE*);
+ // Set the Singleton instance.
+
static void dump (void);
// Dump the state of the object.
@@ -45,6 +48,48 @@ protected:
static LOCK ace_singleton_lock_;
// Lock the creation of the singleton.
#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+
+ static TYPE *&instance_i (void);
+ // Get pointer to the Singleton instance
+
+ static LOCK &singleton_lock_ (void);
+ // Get reference to Singleton lock;
+};
+
+template <class TYPE, class LOCK, ACE_Singleton_Strategy MEMORY>
+class ACE_SingletonEx
+ // = TITLE
+ // A Singleton Adapter that can allocate memory either off the
+ // heap or out of thread-specific storage.
+ //
+ // = DESCRIPTION
+ // Uses the Adapter pattern to turn ordinary classes into
+ // Singletons optimized with the Double-Check pattern.
+{
+public:
+ static TYPE *instance (void);
+ // Global access point to the Singleton.
+
+ static TYPE *instance (TYPE*);
+ // Set the Singleton instance.
+
+ static void dump (void);
+ // Dump the state of the object.
+
+protected:
+#if !defined (ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES)
+ static TYPE *instance_;
+ // Pointer to the Singleton instance.
+
+ static LOCK ace_singletonex_lock_;
+ // Lock the creation of the singleton.
+#endif /* ACE_LACKS_STATIC_DATA_MEMBER_TEMPLATES */
+
+ static TYPE *&instance_i (void);
+ // Get pointer to the SingletonEx instance.
+
+ static LOCK &singleton_lock_ (void);
+ // Get reference to SingletonEx lock;
};
#if defined (__ACE_INLINE__)
diff --git a/ace/config-aix-4.1.x.h b/ace/config-aix-4.1.x.h
index 56eda85cacc..eac4691d2b3 100644
--- a/ace/config-aix-4.1.x.h
+++ b/ace/config-aix-4.1.x.h
@@ -106,7 +106,7 @@
#define ACE_HAS_GETRUSAGE
// EYE assume it does for now.
-#define ACE_LACKS_PTHREAD_THR_SIGSETMASK
+#define ACE_HAS_SIGTHREADMASK
#define ACE_HAS_PTHREADS
#define ACE_LACKS_RWLOCK_T
#define ACE_PTHREADS_MAP
diff --git a/ace/config-aix-4.2.x.h b/ace/config-aix-4.2.x.h
index 2d6fa718f14..e7356f6b030 100644
--- a/ace/config-aix-4.2.x.h
+++ b/ace/config-aix-4.2.x.h
@@ -107,7 +107,7 @@
#define ACE_HAS_GETRUSAGE
// EYE assume it does for now.
-#define ACE_LACKS_PTHREAD_THR_SIGSETMASK
+#define ACE_HAS_SIGTHREADMASK
#define ACE_HAS_PTHREADS
#define ACE_LACKS_RWLOCK_T
#define ACE_PTHREADS_MAP