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') 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 670d03ceb83b92c9bb98d10bb37fba6f75971a2f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 15 Jan 2013 14:28:32 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system fixed LLExtendableRecording to actually accumulator recording time period renamed and updated LLStopWatchControlsMixin::initTo to setPlayState --- indra/llcommon/lltracerecording.cpp | 42 +++++++++++++++++++++--------------- indra/llcommon/lltracerecording.h | 21 +++++++++--------- indra/newview/llviewerassetstats.cpp | 2 +- 3 files changed, 36 insertions(+), 29 deletions(-) (limited to 'indra') diff --git a/indra/llcommon/lltracerecording.cpp b/indra/llcommon/lltracerecording.cpp index ddd25bfe87..f45226eb9a 100644 --- a/indra/llcommon/lltracerecording.cpp +++ b/indra/llcommon/lltracerecording.cpp @@ -60,7 +60,7 @@ Recording::Recording( const Recording& other ) mStackTimers = other.mStackTimers; mMemStats = other.mMemStats; - LLStopWatchControlsMixin::initTo(other.getPlayState()); + LLStopWatchControlsMixin::setPlayState(other.getPlayState()); } @@ -345,14 +345,14 @@ U32 Recording::getSampleCount( const TraceType >& st // PeriodicRecording /////////////////////////////////////////////////////////////////////// -PeriodicRecording::PeriodicRecording( S32 num_periods, EStopWatchState state) +PeriodicRecording::PeriodicRecording( S32 num_periods, EPlayState state) : mNumPeriods(num_periods), mCurPeriod(0), mTotalValid(false), mRecordingPeriods( new Recording[num_periods]) { llassert(mNumPeriods > 0); - initTo(state); + setPlayState(state); } PeriodicRecording::PeriodicRecording(PeriodicRecording& other) @@ -377,7 +377,7 @@ PeriodicRecording::~PeriodicRecording() void PeriodicRecording::nextPeriod() { - EStopWatchState play_state = getPlayState(); + EPlayState play_state = getPlayState(); Recording& old_recording = getCurRecordingPeriod(); mCurPeriod = (mCurPeriod + 1) % mNumPeriods; old_recording.splitTo(getCurRecordingPeriod()); @@ -458,8 +458,14 @@ void PeriodicRecording::splitFrom(PeriodicRecording& other) void ExtendableRecording::extend() { + // stop recording to get latest data + mPotentialRecording.stop(); + // push the data back to accepted recording mAcceptedRecording.appendRecording(mPotentialRecording); + // flush data, so we can start from scratch mPotentialRecording.reset(); + // go back to play state we were in initially + mPotentialRecording.setPlayState(getPlayState()); } void ExtendableRecording::start() @@ -514,7 +520,7 @@ PeriodicRecording& get_frame_recording() void LLStopWatchControlsMixinCommon::start() { - switch (mState) + switch (mPlayState) { case STOPPED: handleReset(); @@ -530,12 +536,12 @@ void LLStopWatchControlsMixinCommon::start() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::stop() { - switch (mState) + switch (mPlayState) { case STOPPED: break; @@ -549,12 +555,12 @@ void LLStopWatchControlsMixinCommon::stop() llassert(false); break; } - mState = STOPPED; + mPlayState = STOPPED; } void LLStopWatchControlsMixinCommon::pause() { - switch (mState) + switch (mPlayState) { case STOPPED: break; @@ -567,12 +573,12 @@ void LLStopWatchControlsMixinCommon::pause() llassert(false); break; } - mState = PAUSED; + mPlayState = PAUSED; } void LLStopWatchControlsMixinCommon::resume() { - switch (mState) + switch (mPlayState) { case STOPPED: handleStart(); @@ -586,12 +592,12 @@ void LLStopWatchControlsMixinCommon::resume() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::restart() { - switch (mState) + switch (mPlayState) { case STOPPED: handleReset(); @@ -608,7 +614,7 @@ void LLStopWatchControlsMixinCommon::restart() llassert(false); break; } - mState = STARTED; + mPlayState = STARTED; } void LLStopWatchControlsMixinCommon::reset() @@ -616,21 +622,23 @@ void LLStopWatchControlsMixinCommon::reset() handleReset(); } -void LLStopWatchControlsMixinCommon::initTo( EStopWatchState state ) +void LLStopWatchControlsMixinCommon::setPlayState( EPlayState state ) { switch(state) { case STOPPED: + stop(); break; case PAUSED: + pause(); break; case STARTED: - handleStart(); + start(); break; default: llassert(false); break; } - mState = state; + mPlayState = state; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index aa3200e5ad..e6b5e85f90 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -39,7 +39,7 @@ class LLStopWatchControlsMixinCommon public: virtual ~LLStopWatchControlsMixinCommon() {} - enum EStopWatchState + enum EPlayState { STOPPED, PAUSED, @@ -53,19 +53,18 @@ public: virtual void restart(); virtual void reset(); - bool isStarted() const { return mState == STARTED; } - bool isPaused() const { return mState == PAUSED; } - bool isStopped() const { return mState == STOPPED; } - EStopWatchState getPlayState() const { return mState; } + bool isStarted() const { return mPlayState == STARTED; } + bool isPaused() const { return mPlayState == PAUSED; } + bool isStopped() const { return mPlayState == STOPPED; } + EPlayState getPlayState() const { return mPlayState; } + // force play state to specific value by calling appropriate handle* methods + void setPlayState(EPlayState state); protected: LLStopWatchControlsMixinCommon() - : mState(STOPPED) + : mPlayState(STOPPED) {} - // derived classes can call this from their copy constructor in order - // to duplicate play state of source - void initTo(EStopWatchState state); private: // trigger active behavior (without reset) virtual void handleStart(){}; @@ -74,7 +73,7 @@ private: // clear accumulated state, can be called while started virtual void handleReset(){}; - EStopWatchState mState; + EPlayState mPlayState; }; template @@ -245,7 +244,7 @@ namespace LLTrace : public LLStopWatchControlsMixin { public: - PeriodicRecording(S32 num_periods, EStopWatchState state = STOPPED); + PeriodicRecording(S32 num_periods, EPlayState state = STOPPED); PeriodicRecording(PeriodicRecording& recording); ~PeriodicRecording(); diff --git a/indra/newview/llviewerassetstats.cpp b/indra/newview/llviewerassetstats.cpp index b4da9521f4..890394dd22 100644 --- a/indra/newview/llviewerassetstats.cpp +++ b/indra/newview/llviewerassetstats.cpp @@ -297,7 +297,7 @@ LLViewerAssetStats::LLViewerAssetStats(const LLViewerAssetStats & src) it->second.makeUnique(); } - LLStopWatchControlsMixin::initTo(src.getPlayState()); + LLStopWatchControlsMixin::setPlayState(src.getPlayState()); } void LLViewerAssetStats::handleStart() -- cgit v1.2.3