summaryrefslogtreecommitdiff
path: root/indra/llcommon/llmemory.h
diff options
context:
space:
mode:
authorKent Quirk <q@lindenlab.com>2009-01-05 18:59:12 +0000
committerKent Quirk <q@lindenlab.com>2009-01-05 18:59:12 +0000
commit667ca55bad0108c4bdf8f007b89e1a52fc766aad (patch)
tree7bd62ac8d9af079c3994565f3f200ccc250bbc28 /indra/llcommon/llmemory.h
parent95f365789f4cebc7bd97ccefd538f14d481a8373 (diff)
svn merge -r106715:HEAD svn+ssh://svn.lindenlab.com/svn/linden/branches/q/notifications-merge-r106715 . QAR-1149 -- Final merge of notifications to trunk.
Diffstat (limited to 'indra/llcommon/llmemory.h')
-rw-r--r--indra/llcommon/llmemory.h59
1 files changed, 32 insertions, 27 deletions
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h
index cc57e658fb..3f3dd33ee3 100644
--- a/indra/llcommon/llmemory.h
+++ b/indra/llcommon/llmemory.h
@@ -409,53 +409,58 @@ protected:
//
// class Foo: public LLSingleton<Foo>{};
//
-// Foo* instance = Foo::getInstance();
+// Foo& instance = Foo::instance();
//
-// The second way is to define a seperate class that exposes the singleton
-// interface:
+// The second way is to use the singleton class directly, without inheritance:
//
-// class FooSingleton: public LLSingleton<Foo>{};
+// typedef LLSingleton<Foo> FooSingleton;
//
-// Foo* instance = FooSingleton::getInstance();
+// Foo& instance = FooSingleton::instance();
+//
+// In this case, the class being managed as a singleton needs to provide an
+// initSingleton() method since the LLSingleton virtual method won't be
+// available
//
// As currently written, it is not thread-safe.
-#if LL_WINDOWS && _MSC_VER < 1400 // this is Visual C++ 2003 or earlier
-// workaround for VC7 compiler bug
-// adapted from http://www.codeproject.com/KB/tips/VC2003MeyersSingletonBug.aspx
-// our version doesn't introduce a nested struct so that you can still declare LLSingleton<MyClass>
-// a friend and hide your constructor
-
template <typename T>
class LLSingleton
{
public:
- static T* getInstance()
+ virtual ~LLSingleton() {}
+#ifdef LL_MSVC7
+// workaround for VC7 compiler bug
+// adapted from http://www.codeproject.com/KB/tips/VC2003MeyersSingletonBug.aspx
+// our version doesn't introduce a nested struct so that you can still declare LLSingleton<MyClass>
+// a friend and hide your constructor
+ static T* getInstance()
{
LLSingleton<T> singleton;
- return singleton.get();
- }
-private:
- T* get()
- {
- static T instance;
- return &instance;
+ return singleton.vsHack();
}
-};
+ T* vsHack()
#else
-
-template <typename T>
-class LLSingleton
-{
-public:
static T* getInstance()
+#endif
{
static T instance;
+ static bool needs_init = true;
+ if (needs_init)
+ {
+ needs_init = false;
+ instance.initSingleton();
+ }
return &instance;
}
-};
-#endif
+ static T& instance()
+ {
+ return *getInstance();
+ }
+
+private:
+ virtual void initSingleton() {}
+};
//----------------------------------------------------------------------------