summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsingleton.h
diff options
context:
space:
mode:
authorRichard Linden <none@none>2014-03-24 19:23:34 -0700
committerRichard Linden <none@none>2014-03-24 19:23:34 -0700
commite5bbdafdeda0f2e6bbe97d59a24ca398b54c31eb (patch)
tree359719c76abf090fb8cc5ae912ed013b64cb8fc7 /indra/llcommon/llsingleton.h
parent31a3a3da5db077c4d9b8fe06a18de98c822db6ab (diff)
parent5b846ed2a6dce6c5801aa74d0f36a1c7525fbcba (diff)
merge with release
Diffstat (limited to 'indra/llcommon/llsingleton.h')
-rwxr-xr-xindra/llcommon/llsingleton.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/indra/llcommon/llsingleton.h b/indra/llcommon/llsingleton.h
index 40002313f1..6e6291a165 100755
--- a/indra/llcommon/llsingleton.h
+++ b/indra/llcommon/llsingleton.h
@@ -67,6 +67,11 @@ private:
INITIALIZED,
DELETED
} EInitState;
+
+ static DERIVED_TYPE* constructSingleton()
+ {
+ return new DERIVED_TYPE();
+ }
// stores pointer to singleton instance
struct SingletonLifetimeManager
@@ -79,7 +84,7 @@ private:
static void construct()
{
sData.mInitState = CONSTRUCTING;
- sData.mInstance = new DERIVED_TYPE();
+ sData.mInstance = constructSingleton();
sData.mInitState = INITIALIZING;
}
@@ -138,18 +143,21 @@ public:
llassert(false);
return NULL;
case CONSTRUCTING:
- llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl;
+ LL_ERRS() << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << LL_ENDL;
return NULL;
case INITIALIZING:
// go ahead and flag ourselves as initialized so we can be reentrant during initialization
sData.mInitState = INITIALIZED;
+ // initialize singleton after constructing it so that it can reference other singletons which in turn depend on it,
+ // thus breaking cyclic dependencies
sData.mInstance->initSingleton();
return sData.mInstance;
case INITIALIZED:
return sData.mInstance;
case DELETED:
- llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl;
+ LL_WARNS() << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << LL_ENDL;
SingletonLifetimeManager::construct();
+ // same as first time construction
sData.mInitState = INITIALIZED;
sData.mInstance->initSingleton();
return sData.mInstance;
@@ -190,6 +198,8 @@ private:
struct SingletonData
{
+ // explicitly has a default constructor so that member variables are zero initialized in BSS
+ // and only changed by singleton logic, not constructor running during startup
EInitState mInitState;
DERIVED_TYPE* mInstance;
};