From cda2cdda511eb2f7a58e284db2c852fd4a3808ae Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 3 Jan 2013 00:30:54 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system made fast timer stack thread local added LLThreadLocalSingleton made LLThreadLocalPointer obey pointer rules for const added LLThreadLocalSingletonPointer for fast thread local pointers --- indra/llcommon/llthreadlocalstorage.h | 254 ++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 indra/llcommon/llthreadlocalstorage.h (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h new file mode 100644 index 0000000000..fdf0c18085 --- /dev/null +++ b/indra/llcommon/llthreadlocalstorage.h @@ -0,0 +1,254 @@ +/** + * @file llthreadlocalstorage.h + * @author Richard + * @brief Class wrappers for thread local storage + * + * $LicenseInfo:firstyear=2004&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#ifndef LL_LLTHREADLOCALSTORAGE_H +#define LL_LLTHREADLOCALSTORAGE_H + +#include "llinstancetracker.h" +#include "llapr.h" + +class LLThreadLocalPointerBase : public LLInstanceTracker +{ +public: + LLThreadLocalPointerBase() + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) + : mThreadKey(NULL) + { + if (sInitialized) + { + initStorage(); + } + } + + ~LLThreadLocalPointerBase() + { + destroyStorage(); + } + + static void initAllThreadLocalStorage(); + static void destroyAllThreadLocalStorage(); + +protected: + void set(void* value); + + LL_FORCE_INLINE void* get() const + { + // llassert(sInitialized); + void* ptr; + apr_status_t result = + apr_threadkey_private_get(&ptr, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to get thread local data" << llendl; + } + return ptr; + } + + void initStorage(); + void destroyStorage(); + +protected: + apr_threadkey_t* mThreadKey; + static bool sInitialized; +}; + +template +class LLThreadLocalPointer : public LLThreadLocalPointerBase +{ +public: + + LLThreadLocalPointer() + {} + + explicit LLThreadLocalPointer(T* value) + { + set(value); + } + + + LLThreadLocalPointer(const LLThreadLocalPointer& other) + : LLThreadLocalPointerBase(other) + { + set(other.get()); + } + + LL_FORCE_INLINE T* get() const + { + return (T*)LLThreadLocalPointerBase::get(); + } + + T* operator -> () const + { + return (T*)get(); + } + + T& operator*() const + { + return *(T*)get(); + } + + LLThreadLocalPointer& operator = (T* value) + { + set((void*)value); + return *this; + } + + bool operator ==(const T* other) const + { + if (!sInitialized) return false; + return get() == other; + } +}; + +template +class LLThreadLocalSingleton +{ + typedef enum e_init_state + { + UNINITIALIZED = 0, + CONSTRUCTING, + INITIALIZING, + INITIALIZED, + DELETED + } EInitState; + +public: + LLThreadLocalSingleton() + {} + + virtual ~LLThreadLocalSingleton() + { + sInstance = NULL; + sInitState = DELETED; + } + + static void deleteSingleton() + { + delete sInstance; + sInstance = NULL; + sInitState = DELETED; + } + + static DERIVED_TYPE* getInstance() + { + if (sInitState == CONSTRUCTING) + { + llerrs << "Tried to access singleton " << typeid(DERIVED_TYPE).name() << " from singleton constructor!" << llendl; + } + + if (sInitState == DELETED) + { + llwarns << "Trying to access deleted singleton " << typeid(DERIVED_TYPE).name() << " creating new instance" << llendl; + } + + if (!sInstance) + { + sInitState = CONSTRUCTING; + sInstance = new DERIVED_TYPE(); + sInitState = INITIALIZING; + sInstance->initSingleton(); + sInitState = INITIALIZED; + } + + return sInstance; + } + + static DERIVED_TYPE* getIfExists() + { + return sInstance; + } + + // 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 sInitState == 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; + } +private: + LLThreadLocalSingleton(const LLThreadLocalSingleton& other); + virtual void initSingleton() {} + + static __declspec(thread) DERIVED_TYPE* sInstance; + static __declspec(thread) EInitState sInitState; +}; + +template +__declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; + +template +__declspec(thread) typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; + +template +class LLThreadLocalSingletonPointer +{ +public: + void operator =(DERIVED_TYPE* value) + { + sInstance = value; + } + + LL_FORCE_INLINE static DERIVED_TYPE* getInstance() + { + return sInstance; + } + + LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) + { + sInstance = instance; + } + +private: + static __declspec(thread) DERIVED_TYPE* sInstance; +}; + +template +__declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; + +#endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3 From 6e82bb7789c1e046dcfb97c6773150df110153f8 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Jan 2013 22:34:34 +0000 Subject: fixing linux compile errors for llcommon after LLTrace work --- indra/llcommon/llthreadlocalstorage.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index fdf0c18085..5a38d54eea 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -215,15 +215,28 @@ private: LLThreadLocalSingleton(const LLThreadLocalSingleton& other); virtual void initSingleton() {} +#ifdef LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; static __declspec(thread) EInitState sInitState; +#elif LL_LINUX + static __thread DERIVED_TYPE* sInstance; + static __thread EInitState sInitState; +#endif }; +#ifdef LL_WINDOWS template __declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __declspec(thread) typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#elif LL_LINUX +template +__thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; + +template +__thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +#endif template class LLThreadLocalSingletonPointer @@ -245,10 +258,18 @@ public: } private: +#ifdef LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; +#elif LL_LINUX + static __thread DERIVED_TYPE* sInstance; +#endif }; template +#ifdef LL_WINDOWS __declspec(thread) DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#elif LL_LINUX +__thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; +#endif #endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3 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/llthreadlocalstorage.h') 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 From a74509355669d059d2645d3239c9499db6818b88 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 15 Jan 2013 10:12:23 -0800 Subject: Attempted fix for thread local storage on OS X --- indra/llcommon/llthreadlocalstorage.h | 58 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 91f45d4f5f..c8b7c5e229 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -151,15 +151,17 @@ public: virtual ~LLThreadLocalSingleton() { - sInstance = NULL; +#if LL_DARWIN + //pthread_setspecific(sInstanceKey, NULL); +#else + sInstance = NULL; +#endif setInitState(DELETED); } static void deleteSingleton() { - delete sInstance; - sInstance = NULL; - setInitState(DELETED); + delete getIfExists(); } static DERIVED_TYPE* getInstance() @@ -178,9 +180,24 @@ public: if (!getIfExists()) { setInitState(CONSTRUCTING); - sInstance = new DERIVED_TYPE(); + DERIVED_TYPE* instancep = new DERIVED_TYPE(); +#if LL_DARWIN + /*static S32 sKeyCreated = pthread_key_create(&sInstanceKey, NULL); + if (sKeyCreated != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + + S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); + if (result != 0) + { + llerrs << "Could not set thread local storage" << llendl; + }*/ +#else + sInstance = instancep; +#endif setInitState(INITIALIZING); - sInstance->initSingleton(); + instancep->initSingleton(); setInitState(INITIALIZED); } @@ -190,7 +207,7 @@ public: static DERIVED_TYPE* getIfExists() { #if LL_DARWIN - return sInstance.get(); + return NULL;//(DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -217,10 +234,23 @@ public: return getInitState() == DELETED; } private: +#if LL_DARWIN + static EInitState& threadLocalInitState() + { + /*static S32 sKeyCreated = pthread_key_create(&sInitStateKey, NULL); + if (sKeyCreated != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + return *(EInitState*)pthread_getspecific(sInitStateKey);*/ + static EInitState state; + return state; + } +#endif static EInitState getInitState() { #if LL_DARWIN - return (EInitState)(int)sInitState.get(); + return threadLocalInitState(); #else return sInitState; #endif @@ -229,7 +259,7 @@ private: static void setInitState(EInitState state) { #if LL_DARWIN - sInitState = (int*)state; + threadLocalInitState() = state; #else sInitState = state; #endif @@ -244,8 +274,8 @@ private: static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; #elif LL_DARWIN - static LLThreadLocalPointer sInstance; - static LLThreadLocalPointer sInitState; + //static pthread_key_t sInstanceKey; + //static pthread_key_t sInitStateKey; #endif }; @@ -262,11 +292,11 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; #elif LL_DARWIN -template -LLThreadLocalPointer LLThreadLocalSingleton::sInstance; +/*template +pthread_key_t LLThreadLocalSingleton::sInstanceKey; template -LLThreadLocalPointer LLThreadLocalSingleton::sInitState; +pthread_key_t LLThreadLocalSingleton::sInitStateKey;*/ #endif template -- cgit v1.2.3 From a0413bdef71d804bbf008cf319f54a5a47efb29c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 17 Jan 2013 20:04:26 -0800 Subject: fix for mac thread local storage --- indra/llcommon/llthreadlocalstorage.h | 74 +++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 26 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index c8b7c5e229..fd44589299 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -152,7 +152,7 @@ public: virtual ~LLThreadLocalSingleton() { #if LL_DARWIN - //pthread_setspecific(sInstanceKey, NULL); + pthread_setspecific(sInstanceKey, NULL); #else sInstance = NULL; #endif @@ -182,17 +182,12 @@ public: setInitState(CONSTRUCTING); DERIVED_TYPE* instancep = new DERIVED_TYPE(); #if LL_DARWIN - /*static S32 sKeyCreated = pthread_key_create(&sInstanceKey, NULL); - if (sKeyCreated != 0) - { - llerrs << "Could not create thread local storage" << llendl; - } - + createTLSInstance(); S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); if (result != 0) { llerrs << "Could not set thread local storage" << llendl; - }*/ + } #else sInstance = instancep; #endif @@ -207,7 +202,7 @@ public: static DERIVED_TYPE* getIfExists() { #if LL_DARWIN - return NULL;//(DERIVED_TYPE*)pthread_getspecific(sInstanceKey); + return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -235,22 +230,29 @@ public: } private: #if LL_DARWIN - static EInitState& threadLocalInitState() + 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 sKeyCreated = pthread_key_create(&sInitStateKey, NULL); - if (sKeyCreated != 0) + static S32 key_created = pthread_key_create(&sInstanceKey, NULL); + if (key_created != 0) { llerrs << "Could not create thread local storage" << llendl; } - return *(EInitState*)pthread_getspecific(sInitStateKey);*/ - static EInitState state; - return state; } #endif static EInitState getInitState() { #if LL_DARWIN - return threadLocalInitState(); + createTLSInitState(); + return (EInitState)(int)pthread_getspecific(sInitStateKey); #else return sInitState; #endif @@ -259,7 +261,8 @@ private: static void setInitState(EInitState state) { #if LL_DARWIN - threadLocalInitState() = state; + createTLSInitState(); + pthread_setspecific(sInitStateKey, (void*)state); #else sInitState = state; #endif @@ -274,8 +277,8 @@ private: static __thread DERIVED_TYPE* sInstance; static __thread EInitState sInitState; #elif LL_DARWIN - //static pthread_key_t sInstanceKey; - //static pthread_key_t sInitStateKey; + static pthread_key_t sInstanceKey; + static pthread_key_t sInitStateKey; #endif }; @@ -292,11 +295,12 @@ __thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; template __thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; #elif LL_DARWIN -/*template +template pthread_key_t LLThreadLocalSingleton::sInstanceKey; template -pthread_key_t LLThreadLocalSingleton::sInitStateKey;*/ +pthread_key_t LLThreadLocalSingleton::sInitStateKey; + #endif template @@ -305,13 +309,14 @@ class LLThreadLocalSingletonPointer public: void operator =(DERIVED_TYPE* value) { - sInstance = value; + setInstance(value); } - + LL_FORCE_INLINE static DERIVED_TYPE* getInstance() { #if LL_DARWIN - return sInstance.get(); + createTLSKey(); + return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else return sInstance; #endif @@ -319,7 +324,12 @@ public: LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) { +#if LL_DARWIN + createTLSKey(); + pthread_setspecific(sInstanceKey, (void*)instance); +#else sInstance = instance; +#endif } private: @@ -328,7 +338,19 @@ private: #elif LL_LINUX static __thread DERIVED_TYPE* sInstance; #elif LL_DARWIN - static LLThreadLocalPointer sInstance; + static void TLSError() + { + llerrs << "Could not create thread local storage" << llendl; + } + static void createTLSKey() + { + static S32 key_created = pthread_key_create(&sInstanceKey, NULL); + if (key_created != 0) + { + llerrs << "Could not create thread local storage" << llendl; + } + } + static pthread_key_t sInstanceKey; #endif }; @@ -340,7 +362,7 @@ template __thread DERIVED_TYPE* LLThreadLocalSingletonPointer::sInstance = NULL; #elif LL_DARWIN template -LLThreadLocalPointer LLThreadLocalSingletonPointer::sInstance; +pthread_key_t LLThreadLocalSingletonPointer::sInstanceKey; #endif #endif // LL_LLTHREADLOCALSTORAGE_H -- cgit v1.2.3 From 6fc355814f3dec7351fd629f4d263c46cfb0e160 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 22 Jan 2013 20:30:05 -0800 Subject: SH-3275 WIP Update viewer metrics system to be more flexible fix for mac unit tests failing --- indra/llcommon/llthreadlocalstorage.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index fd44589299..4873b2740d 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -177,12 +177,14 @@ public: 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 - createTLSInstance(); S32 result = pthread_setspecific(sInstanceKey, (void*)instancep); if (result != 0) { -- cgit v1.2.3 From 9ae76d12157641033431381959ef4f798a119b8d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 29 May 2013 17:00:50 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics fixed copy construction behavior of Recordings to not zero out data split measurement into event and sample, with sample representing a continuous function --- indra/llcommon/llthreadlocalstorage.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 4873b2740d..471784749b 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -131,6 +131,10 @@ public: if (!sInitialized) return false; return get() == other; } + + bool isNull() const { return !sInitialized || get() == NULL; } + + bool notNull() const { return sInitialized && get() != NULL; } }; template -- cgit v1.2.3 From ae355188327515d53b9c15c27ed576829fce3668 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 30 May 2013 18:30:11 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics fixed LLTrace::ExtendablePeriodicRecording::extend() to include *all* frame extensions gated SlaveThreadRecorder pushing to master based on master update rate reverted changes to LLThreadLocalSingletonPointer to not use offset-from-default trick --- indra/llcommon/llthreadlocalstorage.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 471784749b..cc67248124 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -313,11 +313,6 @@ template class LLThreadLocalSingletonPointer { public: - void operator =(DERIVED_TYPE* value) - { - setInstance(value); - } - LL_FORCE_INLINE static DERIVED_TYPE* getInstance() { #if LL_DARWIN @@ -328,7 +323,7 @@ public: #endif } - LL_FORCE_INLINE static void setInstance(DERIVED_TYPE* instance) + static void setInstance(DERIVED_TYPE* instance) { #if LL_DARWIN createTLSKey(); @@ -339,6 +334,7 @@ public: } private: + #if LL_WINDOWS static __declspec(thread) DERIVED_TYPE* sInstance; #elif LL_LINUX -- cgit v1.2.3 From 8bddaeec6647e735415f9bd72a4e1313e11fe720 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 22 Jun 2013 12:00:18 -0700 Subject: fixed scene load monitor resetting to eagerly due to spurious camer amotion pulled swap() out of ui time block cleaned up internal lltrace dependencies, factored out common accumulator definitions --- indra/llcommon/llthreadlocalstorage.h | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index a15f9185b1..d6399d5131 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -145,7 +145,7 @@ public: #if LL_DARWIN pthread_setspecific(sInstanceKey, NULL); #else - sInstance = NULL; + sData.mInstance = NULL; #endif setInitState(DELETED); } @@ -182,7 +182,7 @@ public: llerrs << "Could not set thread local storage" << llendl; } #else - sInstance = instancep; + sData.mInstance = instancep; #endif setInitState(INITIALIZING); instancep->initSingleton(); @@ -197,7 +197,7 @@ public: #if LL_DARWIN return (DERIVED_TYPE*)pthread_getspecific(sInstanceKey); #else - return sInstance; + return sData.mInstance; #endif } @@ -247,7 +247,7 @@ private: createTLSInitState(); return (EInitState)(int)pthread_getspecific(sInitStateKey); #else - return sInitState; + return sData.mInitState; #endif } @@ -257,18 +257,21 @@ private: createTLSInitState(); pthread_setspecific(sInitStateKey, (void*)state); #else - sInitState = state; + sData.mInitState = state; #endif } LLThreadLocalSingleton(const LLThreadLocalSingleton& other); virtual void initSingleton() {} + struct SingletonData + { + DERIVED_TYPE* mInstance; + EInitState mInitState; + }; #ifdef LL_WINDOWS - static __declspec(thread) DERIVED_TYPE* sInstance; - static __declspec(thread) EInitState sInitState; + static __declspec(thread) SingletonData sData; #elif LL_LINUX - static __thread DERIVED_TYPE* sInstance; - static __thread EInitState sInitState; + static __thread SingletonData sData; #elif LL_DARWIN static pthread_key_t sInstanceKey; static pthread_key_t sInitStateKey; @@ -277,16 +280,10 @@ private: #if LL_WINDOWS template -__declspec(thread) DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; - -template -__declspec(thread) typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +__declspec(thread) typename LLThreadLocalSingleton::SingletonData LLThreadLocalSingleton::sData = {NULL, LLThreadLocalSingleton::UNINITIALIZED}; #elif LL_LINUX template -__thread DERIVED_TYPE* LLThreadLocalSingleton::sInstance = NULL; - -template -__thread typename LLThreadLocalSingleton::EInitState LLThreadLocalSingleton::sInitState = LLThreadLocalSingleton::UNINITIALIZED; +__thread typename LLThreadLocalSingleton::SingletonData LLThreadLocalSingleton::sData = {NULL, LLThreadLocalSingleton::UNINITIALIZED}; #elif LL_DARWIN template pthread_key_t LLThreadLocalSingleton::sInstanceKey; -- cgit v1.2.3 From 2fc422f39ddaca25c69e8cf2092a9d66840379f3 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 30 Jun 2013 13:32:34 -0700 Subject: fixed memory leak due to implementation of LLThreadLocalSingleton removed LLThreadLocalSingleton collapsed all thread recorder classes to single type, LLTrace::ThreadRecorder moved fasttimer stack head to llthreadlocalsingletonpointer via ThreadRecorder --- indra/llcommon/llthreadlocalstorage.h | 169 ---------------------------------- 1 file changed, 169 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') 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 @@ -124,175 +124,6 @@ public: bool notNull() const { return sInitialized && get() != NULL; } }; -template -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 -__declspec(thread) typename LLThreadLocalSingleton::SingletonData LLThreadLocalSingleton::sData = {NULL, LLThreadLocalSingleton::UNINITIALIZED}; -#elif LL_LINUX -template -__thread typename LLThreadLocalSingleton::SingletonData LLThreadLocalSingleton::sData = {NULL, LLThreadLocalSingleton::UNINITIALIZED}; -#elif LL_DARWIN -template -pthread_key_t LLThreadLocalSingleton::sInstanceKey; - -template -pthread_key_t LLThreadLocalSingleton::sInitStateKey; - -#endif - template class LLThreadLocalSingletonPointer { -- cgit v1.2.3 From e340009fc59d59e59b2e8d903a884acb76b178eb Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 9 Aug 2013 17:11:19 -0700 Subject: second phase summer cleaning replace llinfos, lldebugs, etc with new LL_INFOS(), LL_DEBUGS(), etc. --- indra/llcommon/llthreadlocalstorage.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 3b2f5f4193..177e822227 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -157,14 +157,14 @@ private: #elif LL_DARWIN static void TLSError() { - llerrs << "Could not create thread local storage" << llendl; + LL_ERRS() << "Could not create thread local storage" << LL_ENDL; } static void createTLSKey() { static S32 key_created = pthread_key_create(&sInstanceKey, NULL); if (key_created != 0) { - llerrs << "Could not create thread local storage" << llendl; + LL_ERRS() << "Could not create thread local storage" << LL_ENDL; } } static pthread_key_t sInstanceKey; -- cgit v1.2.3 From dc60a7564abf16cbf269e47cfc33ed00c6bb0870 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 24 Oct 2013 14:37:57 -0700 Subject: SH-4577 WIP Interesting: viewer crashed when clicking a offline Conversation containing a shared object potential fix by making instance tracker allow key collisions for LLToastNotifyPanel changed assertion macro to use original unpreprocessed source code renamed instance tracker behavior macros to use LL prefix added RestoreCameraPosOnLogin setting to optionally restore old camera positioning behavior --- indra/llcommon/llthreadlocalstorage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/llthreadlocalstorage.h') diff --git a/indra/llcommon/llthreadlocalstorage.h b/indra/llcommon/llthreadlocalstorage.h index 177e822227..ec3b52c8cb 100644 --- a/indra/llcommon/llthreadlocalstorage.h +++ b/indra/llcommon/llthreadlocalstorage.h @@ -43,7 +43,7 @@ public: } LLThreadLocalPointerBase( const LLThreadLocalPointerBase& other) - : mThreadKey(NULL) + : mThreadKey(NULL) { if (sInitialized) { -- cgit v1.2.3