From 44cc14fbee8c9cb033dcb94d9c54f532427a5768 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Jan 2013 13:11:07 -0800 Subject: fix for mac builds --- indra/llcommon/llthreadlocalstorage.h | 69 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 14 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 5a38d54eea..91f45d4f5f 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -152,43 +152,48 @@ public: virtual ~LLThreadLocalSingleton() { sInstance = NULL; - sInitState = DELETED; + setInitState(DELETED); } static void deleteSingleton() { delete sInstance; sInstance = NULL; - sInitState = DELETED; + setInitState(DELETED); } static DERIVED_TYPE* getInstance() { - if (sInitState == CONSTRUCTING) + EInitState init_state = getInitState(); + if (init_state == CONSTRUCTING) { llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl; } - if (sInitState == DELETED) + if (init_state == DELETED) { llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; } - if (!sInstance) + if (!getIfExists()) { - sInitState = CONSTRUCTING; + setInitState(CONSTRUCTING); sInstance = new DERIVED_TYPE(); - sInitState = INITIALIZING; + setInitState(INITIALIZING); sInstance->initSingleton(); - sInitState = INITIALIZED; + setInitState(INITIALIZED); } - return sInstance; + return getIfExists(); } static DERIVED_TYPE* getIfExists() { +#if LL_DARWIN + return sInstance.get(); +#else return sInstance; +#endif } // Reference version of getInstance() @@ -202,16 +207,33 @@ public: // Use this to avoid accessing singletons before the can safely be constructed static bool instanceExists() { - return sInitState == INITIALIZED; + 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 sInitState == DELETED; + return getInitState() == DELETED; } private: + static EInitState getInitState() + { +#if LL_DARWIN + return (EInitState)(int)sInitState.get(); +#else + return sInitState; +#endif + } + + static void setInitState(EInitState state) + { +#if LL_DARWIN + sInitState = (int*)state; +#else + sInitState = state; +#endif + } LLThreadLocalSingleton(const LLThreadLocalSingleton& other); virtual void initSingleton() {} @@ -221,10 +243,13 @@ private: #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; +#elif LL_DARWIN + static LLThreadLocalPointer sInstance; + static LLThreadLocalPointer sInitState; #endif }; -#ifdef LL_WINDOWS +#if LL_WINDOWS template __declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; @@ -236,6 +261,12 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#elif LL_DARWIN +template +LLThreadLocalPointer LLThreadLocalSingleton::sInstance; + +template +LLThreadLocalPointer LLThreadLocalSingleton::sInitState; #endif template @@ -249,7 +280,11 @@ public: LL_FORCE_INLINE static DERIVED_TYPE* getInstance() { +#if LL_DARWIN + return sInstance.get(); +#else return sInstance; +#endif } LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) @@ -258,18 +293,24 @@ public: } private: -#ifdef LL_WINDOWS +#if LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; +#elif LL_DARWIN + static LLThreadLocalPointer sInstance; #endif }; +#if LL_WINDOWS template -#ifdef LL_WINDOWS __declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; #elif LL_LINUX +template __thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#elif LL_DARWIN +template +LLThreadLocalPointer LLThreadLocalSingletonPointer::sInstance; #endif #endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3