Apply Aleric's fix to llsingleton.h to fix issues with AISync stuff
Modified to diff with LL better.
This commit is contained in:
@@ -102,10 +102,10 @@ private:
|
|||||||
// stores pointer to singleton instance
|
// stores pointer to singleton instance
|
||||||
struct SingletonLifetimeManager
|
struct SingletonLifetimeManager
|
||||||
{
|
{
|
||||||
SingletonLifetimeManager()
|
/*SingletonLifetimeManager()
|
||||||
{
|
{
|
||||||
construct();
|
construct();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
static void construct()
|
static void construct()
|
||||||
{
|
{
|
||||||
@@ -115,14 +115,14 @@ private:
|
|||||||
sData.mInitState = INITIALIZING;
|
sData.mInitState = INITIALIZING;
|
||||||
}
|
}
|
||||||
|
|
||||||
~SingletonLifetimeManager()
|
/*~SingletonLifetimeManager()
|
||||||
{
|
{
|
||||||
SingletonData& sData(getData());
|
SingletonData& sData(getData());
|
||||||
if (sData.mInitState != DELETED)
|
if (sData.mInitState != DELETED)
|
||||||
{
|
{
|
||||||
deleteSingleton();
|
deleteSingleton();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -178,33 +178,28 @@ public:
|
|||||||
|
|
||||||
static DERIVED_TYPE* getInstance()
|
static DERIVED_TYPE* getInstance()
|
||||||
{
|
{
|
||||||
static SingletonLifetimeManager sLifeTimeMgr;
|
//static SingletonLifetimeManager sLifeTimeMgr;
|
||||||
SingletonData& sData(getData());
|
SingletonData& sData(getData());
|
||||||
|
|
||||||
switch (sData.mInitState)
|
switch (sData.mInitState)
|
||||||
{
|
{
|
||||||
case UNINITIALIZED:
|
|
||||||
// should never be uninitialized at this point
|
|
||||||
llassert(false);
|
|
||||||
return NULL;
|
|
||||||
case CONSTRUCTING:
|
case CONSTRUCTING:
|
||||||
llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << LL_ENDL;
|
llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << LL_ENDL;
|
||||||
return NULL;
|
return NULL;
|
||||||
case INITIALIZING:
|
case INITIALIZING:
|
||||||
// go ahead and flag ourselves as initialized so we can be reentrant during initialization
|
llwarns << "Using singleton " << typeid(DERIVED_TYPE).name() << " during its own initialization, before its initialization completed!" << LL_ENDL;
|
||||||
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;
|
return sData.mInstance;
|
||||||
case INITIALIZED:
|
case INITIALIZED:
|
||||||
return sData.mInstance;
|
return sData.mInstance;
|
||||||
case DELETED:
|
case DELETED:
|
||||||
llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << LL_ENDL;
|
llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << LL_ENDL;
|
||||||
|
case UNINITIALIZED:
|
||||||
|
// This must be the first time we get here.
|
||||||
SingletonLifetimeManager::construct();
|
SingletonLifetimeManager::construct();
|
||||||
// same as first time construction
|
// same as first time construction
|
||||||
sData.mInitState = INITIALIZED;
|
// Singu note: LL sets the state to INITIALIZED here *already* - which avoids the warning below, but is clearly total bullshit.
|
||||||
sData.mInstance->initSingleton();
|
sData.mInstance->initSingleton();
|
||||||
|
sData.mInitState = INITIALIZED;
|
||||||
return sData.mInstance;
|
return sData.mInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user