summaryrefslogtreecommitdiff
path: root/indra/llcommon/llthreadlocalstorage.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llthreadlocalstorage.h')
-rw-r--r--indra/llcommon/llthreadlocalstorage.h169
1 files changed, 0 insertions, 169 deletions
diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h
index d6399d5131..3b2f5f4193 100644
--- a/indra/llcommon/llthreadlocalstorage.h
+++ b/indra/llcommon/llthreadlocalstorage.h
@@ -125,175 +125,6 @@ public:
};
template<typename DERIVED_TYPE>
-class LLThreadLocalSingleton
-{
- typedef enum e_init_state
- {
- UNINITIALIZED = 0,
- CONSTRUCTING,
- INITIALIZING,
- INITIALIZED,
- DELETED
- } EInitState;
-
-public:
- LLThreadLocalSingleton()
- {}
-
- virtual ~LLThreadLocalSingleton()
- {
-#if LL_DARWIN
- pthread_setspecific(sInstanceKey, NULL);
-#else
- sData.mInstance = NULL;
-#endif
- setInitState(DELETED);
- }
-
- static void deleteSingleton()
- {
- delete getIfExists();
- }
-
- static DERIVED_TYPE* getInstance()
- {
- EInitState init_state = getInitState();
- if (init_state == CONSTRUCTING)
- {
- llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl;
- }
-
- if (init_state == DELETED)
- {
- llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl;
- }
-
-#if LL_DARWIN
- createTLSInstance();
-#endif
- if (!getIfExists())
- {
- setInitState(CONSTRUCTING);
- DERIVED_TYPE* instancep = new DERIVED_TYPE();
-#if LL_DARWIN
- S32 result = pthread_setspecific(sInstanceKey, (void*)instancep);
- if (result != 0)
- {
- llerrs << "Could not set thread local storage" << llendl;
- }
-#else
- sData.mInstance = instancep;
-#endif
- setInitState(INITIALIZING);
- instancep->initSingleton();
- setInitState(INITIALIZED);
- }
-
- return getIfExists();
- }
-
- static DERIVED_TYPE* getIfExists()
- {
-#if LL_DARWIN
- return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey);
-#else
- return sData.mInstance;
-#endif
- }
-
- // Reference version of getInstance()
- // Preferred over getInstance() as it disallows checking for NULL
- static DERIVED_TYPE& instance()
- {
- return *getInstance();
- }
-
- // Has this singleton been created uet?
- // Use this to avoid accessing singletons before the can safely be constructed
- static bool instanceExists()
- {
- return getInitState() == INITIALIZED;
- }
-
- // Has this singleton already been deleted?
- // Use this to avoid accessing singletons from a static object's destructor
- static bool destroyed()
- {
- return getInitState() == DELETED;
- }
-private:
-#if LL_DARWIN
- static void createTLSInitState()
- {
- static S32 key_created = pthread_key_create(&sInitStateKey, NULL);
- if (key_created != 0)
- {
- llerrs << "Could not create thread local storage" << llendl;
- }
- }
-
- static void createTLSInstance()
- {
- static S32 key_created = pthread_key_create(&sInstanceKey, NULL);
- if (key_created != 0)
- {
- llerrs << "Could not create thread local storage" << llendl;
- }
- }
-#endif
- static EInitState getInitState()
- {
-#if LL_DARWIN
- createTLSInitState();
- return (EInitState)(int)pthread_getspecific(sInitStateKey);
-#else
- return sData.mInitState;
-#endif
- }
-
- static void setInitState(EInitState state)
- {
-#if LL_DARWIN
- createTLSInitState();
- pthread_setspecific(sInitStateKey, (void*)state);
-#else
- sData.mInitState = state;
-#endif
- }
- LLThreadLocalSingleton(const LLThreadLocalSingleton& other);
- virtual void initSingleton() {}
-
- struct SingletonData
- {
- DERIVED_TYPE* mInstance;
- EInitState mInitState;
- };
-#ifdef LL_WINDOWS
- static __declspec(thread) SingletonData sData;
-#elif LL_LINUX
- static __thread SingletonData sData;
-#elif LL_DARWIN
- static pthread_key_t sInstanceKey;
- static pthread_key_t sInitStateKey;
-#endif
-};
-
-#if LL_WINDOWS
-template<typename DERIVED_TYPE>
-__declspec(thread) typename LLThreadLocalSingleton<DERIVED_TYPE>::SingletonData LLThreadLocalSingleton<DERIVED_TYPE>::sData = {NULL, LLThreadLocalSingleton<DERIVED_TYPE>::UNINITIALIZED};
-#elif LL_LINUX
-template<typename DERIVED_TYPE>
-__thread typename LLThreadLocalSingleton<DERIVED_TYPE>::SingletonData LLThreadLocalSingleton<DERIVED_TYPE>::sData = {NULL, LLThreadLocalSingleton<DERIVED_TYPE>::UNINITIALIZED};
-#elif LL_DARWIN
-template<typename DERIVED_TYPE>
-pthread_key_t LLThreadLocalSingleton<DERIVED_TYPE>::sInstanceKey;
-
-template<typename DERIVED_TYPE>
-pthread_key_t LLThreadLocalSingleton<DERIVED_TYPE>::sInitStateKey;
-
-#endif
-
-template<typename DERIVED_TYPE>
class LLThreadLocalSingletonPointer
{
public: