diff options
author | Monty Brandenberg <monty@lindenlab.com> | 2014-05-22 22:08:54 +0000 |
---|---|---|
committer | Monty Brandenberg <monty@lindenlab.com> | 2014-05-22 22:08:54 +0000 |
commit | 060c728970dc78d30f2cebdbeda7e56ea8de46e2 (patch) | |
tree | 8f00ce1b3bd564bc6cb81a2bc39a081eb3deca35 /indra/llcommon/llsingleton.h | |
parent | f8874d04b8ca238ee99dc464055295cff417a9b2 (diff) | |
parent | 644ca6a0f8a7759119814f88df93b8e838321a12 (diff) |
Merge. Pull in viewer-release after release of 3.7.8
Diffstat (limited to 'indra/llcommon/llsingleton.h')
-rwxr-xr-x | indra/llcommon/llsingleton.h | 16 |
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; }; |