aboutsummaryrefslogtreecommitdiff
path: root/dep/include/zthread/Singleton.h
diff options
context:
space:
mode:
Diffstat (limited to 'dep/include/zthread/Singleton.h')
-rw-r--r--dep/include/zthread/Singleton.h68
1 files changed, 34 insertions, 34 deletions
diff --git a/dep/include/zthread/Singleton.h b/dep/include/zthread/Singleton.h
index b66c9d0898a..b8f0d1ea842 100644
--- a/dep/include/zthread/Singleton.h
+++ b/dep/include/zthread/Singleton.h
@@ -32,7 +32,7 @@ namespace ZThread {
//
// This policy controls how an object is instantiated
// as well as how and when its destroyed. Phoenix-style
-// singletons are not supported easily with type of policy,
+// singletons are not supported easily with type of policy,
// this is intentional since I do not believe that is in
// the true spirit of a singleton.
//
@@ -46,9 +46,9 @@ namespace ZThread {
* @class LocalStaticInstantiation
* @author Eric Crahen <http://www.code-foo.com>
* @date <2003-07-16T17:57:45-0400>
- * @version 2.2.0
+ * @version 2.2.0
*
- * The LocalStaticInstantiation policy allows the creation
+ * The LocalStaticInstantiation policy allows the creation
* and lifetime of an instance of a particular type
* to be managed using static local values. This will
* abide by the standard C++ rules for static objects
@@ -61,12 +61,12 @@ protected:
* Create an instance of an object, using a local static. The
* object will be destroyed by the system.
*
- * @param ptr reference to location to receive the address
+ * @param ptr reference to location to receive the address
* of the allocated object
*/
template <class T>
static void create(T*& ptr) {
-
+
static T instance;
ptr = &instance;
@@ -91,9 +91,9 @@ class StaticInstantiationHelper {
* @class StaticInstantiation
* @author Eric Crahen <http://www.code-foo.com>
* @date <2003-07-16T17:57:45-0400>
- * @version 2.2.0
+ * @version 2.2.0
*
- * The StaticInstantiation policy allows the creation
+ * The StaticInstantiation policy allows the creation
* and lifetime of an instance of a particular type
* to be managed using static instantiation. This will
* abide by the standard C++ rules for static objects
@@ -105,7 +105,7 @@ protected:
/**
* Create an instance of an object using by simply allocating it statically.
*
- * @param ptr reference to location to receive the address
+ * @param ptr reference to location to receive the address
* of the allocated object
*/
template <class T>
@@ -118,32 +118,32 @@ protected:
//! SingletonDestroyer
template <class T>
class Destroyer {
-
+
T* doomed;
-
+
public:
-
+
Destroyer(T* q) : doomed(q) {
assert(doomed);
}
-
+
~Destroyer();
};
template <class T>
Destroyer<T>::~Destroyer() {
-
+
try {
-
+
if(doomed)
delete doomed;
-
+
} catch(...) { }
-
+
doomed = 0;
-
-}
+
+}
/**
@@ -152,10 +152,10 @@ Destroyer<T>::~Destroyer() {
* @date <2003-07-16T17:57:45-0400>
* @version 2.2.0
*
- * The LazyInstantiation policy allows the creation
+ * The LazyInstantiation policy allows the creation
* and lifetime of an instance of a particular type
* to be managed using dynamic allocation and a singleton
- * destroyer. This will abide by the standard C++ rules
+ * destroyer. This will abide by the standard C++ rules
* for static objects lifetimes.
*/
class LazyInstantiation {
@@ -166,33 +166,33 @@ protected:
* destroyed when an associated Destroyer object (allocated
* statically) goes out of scope.
*
- * @param ptr reference to location to receive the address
+ * @param ptr reference to location to receive the address
* of the allocated object
*/
template <class T>
static void create(T*& ptr) {
-
+
ptr = new T;
static Destroyer<T> destroyer(ptr);
-
+
}
};
-
+
/**
* @class Singleton
* @author Eric Crahen <http://www.code-foo.com>
* @date <2003-07-16T17:57:45-0400>
- * @version 2.2.0
+ * @version 2.2.0
*
* Based on the work of John Vlissidles in his book 'Pattern Hatching'
* an article by Douglas Schmidtt on double-checked locking and policy
* templates described by Andrei Alexandrescu.
*
- * This is a thread safe wrapper for creating Singleton classes. The
+ * This is a thread safe wrapper for creating Singleton classes. The
* synchronization method and instantiation methods can be changed
- * easily by specifying different policy implementations as the
+ * easily by specifying different policy implementations as the
* templates parameters.
*
* @code
@@ -200,7 +200,7 @@ protected:
* // Most common Singleton
* Singletion<LonesomeType>
*
- * // Singleton that uses static storage
+ * // Singleton that uses static storage
* Singletion<LonesomeType, StaticInstantiation>
*
* // Single-threaded singleton that uses static storage (Meyers-like)
@@ -213,9 +213,9 @@ class Singleton : private InstantiationPolicy, private NonCopyable {
public:
/**
- * Provide access to the single instance through double-checked locking
+ * Provide access to the single instance through double-checked locking
*
- * @return T* single instance
+ * @return T* single instance
*/
static T* instance();
@@ -226,19 +226,19 @@ T* Singleton<T, InstantiationPolicy, LockType>::instance() {
// Uses local static storage to avoid static construction
// sequence issues. (regaring when the lock is created)
- static T* ptr = 0;
+ static T* ptr = 0;
static LockType lock;
if(!ptr) {
Guard<LockType, LockedScope> g(lock);
- if(!ptr)
+ if(!ptr)
InstantiationPolicy::create(ptr);
}
-
+
return const_cast<T*>(ptr);
-
+
}