summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsingleton.h
diff options
context:
space:
mode:
authorRichard Linden <none@none>2013-11-06 17:22:04 -0800
committerRichard Linden <none@none>2013-11-06 17:22:04 -0800
commitfe518bde8e6db65d3d6b178c200410b1346639a4 (patch)
treed738e12f8391a675d36aae9d59ced8104846008c /indra/llcommon/llsingleton.h
parentea1e1b0925b386cf83178539b8eae9e25c573548 (diff)
parentd9d46d908c0573dbcd45ec2a1bea56966823343b (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;
};