diff options
author | Richard Linden <none@none> | 2012-09-21 18:52:08 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2012-09-21 18:52:08 -0700 |
commit | 735fde8c742188d019e41faf26ff67aab6a24d25 (patch) | |
tree | 2a9b09c54e49a738be17511470dd565c45c41180 /indra/llcommon/llthread.h | |
parent | d5fce3a8093bb101b7a536f3611d3135167b05c4 (diff) |
SH-3275 WIP Run viewer metrics for object update messages
added LLThreadLocalPtr
broke llmutex out into llmutex.h
got primary sampling buffer under thread local storage
Diffstat (limited to 'indra/llcommon/llthread.h')
-rw-r--r-- | indra/llcommon/llthread.h | 171 |
1 files changed, 15 insertions, 156 deletions
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index b52e70ab2e..e2de4c8b85 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -30,21 +30,21 @@ #include "llapp.h" #include "llapr.h" #include "apr_thread_cond.h" - -class LLThread; -class LLMutex; -class LLCondition; - -#if LL_WINDOWS -#define ll_thread_local __declspec(thread) -#else -#define ll_thread_local __thread -#endif +#include "lltrace.h" +#include "llthreadlocalptr.h" class LL_COMMON_API LLThread { private: + friend class LLMutex; static U32 sIDIter; +#if LL_DARWIN + // statically allocated thread local storage not supported in Darwin executable formats +#elif LL_WINDOWS + static U32 __declspec(thread) LLThread::sThreadIndex; +#elif LL_LINUX + static U32 __thread LLThread::sThreadID ; +#endif public: typedef enum e_thread_status @@ -88,6 +88,8 @@ public: U32 getID() const { return mID; } + static LLTrace::ThreadTraceData* getTraceData() { return sTraceData.get(); } + private: BOOL mPaused; @@ -96,7 +98,7 @@ private: protected: std::string mName; - LLCondition* mRunCondition; + class LLCondition* mRunCondition; apr_thread_t *mAPRThreadp; apr_pool_t *mAPRPoolp; @@ -104,6 +106,8 @@ protected: EThreadStatus mStatus; U32 mID; + static LLThreadLocalPtr<LLTrace::ThreadTraceData> sTraceData; + //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. // otherwise it will cause severe memory leaking!!! --bao @@ -135,149 +139,4 @@ protected: //============================================================================ -#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO) - -class LL_COMMON_API LLMutex -{ -public: - typedef enum - { - NO_THREAD = 0xFFFFFFFF - } e_locking_thread; - - LLMutex(apr_pool_t *apr_poolp); // NULL pool constructs a new pool for the mutex - virtual ~LLMutex(); - - void lock(); // blocks - void unlock(); - bool isLocked(); // non-blocking, but does do a lock/unlock so not free - bool isSelfLocked(); //return true if locked in a same thread - U32 lockingThread() const; //get ID of locking thread - -protected: - apr_thread_mutex_t *mAPRMutexp; - mutable U32 mCount; - mutable U32 mLockingThread; - - apr_pool_t *mAPRPoolp; - BOOL mIsLocalPool; - -#if MUTEX_DEBUG - std::map<U32, BOOL> mIsLocked; -#endif -}; - -// Actually a condition/mutex pair (since each condition needs to be associated with a mutex). -class LL_COMMON_API LLCondition : public LLMutex -{ -public: - LLCondition(apr_pool_t *apr_poolp); // Defaults to global pool, could use the thread pool as well. - ~LLCondition(); - - void wait(); // blocks - void signal(); - void broadcast(); - -protected: - apr_thread_cond_t *mAPRCondp; -}; - -class LLMutexLock -{ -public: - LLMutexLock(LLMutex* mutex) - { - mMutex = mutex; - - if(mMutex) - mMutex->lock(); - } - ~LLMutexLock() - { - if(mMutex) - mMutex->unlock(); - } -private: - LLMutex* mMutex; -}; - -//============================================================================ - -void LLThread::lockData() -{ - mRunCondition->lock(); -} - -void LLThread::unlockData() -{ - mRunCondition->unlock(); -} - - -//============================================================================ - -// see llmemory.h for LLPointer<> definition - -class LL_COMMON_API LLThreadSafeRefCount -{ -public: - static void initThreadSafeRefCount(); // creates sMutex - static void cleanupThreadSafeRefCount(); // destroys sMutex - -private: - static LLMutex* sMutex; - -private: - LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented - LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented - -protected: - virtual ~LLThreadSafeRefCount(); // use unref() - -public: - LLThreadSafeRefCount(); - - void ref() - { - if (sMutex) sMutex->lock(); - mRef++; - if (sMutex) sMutex->unlock(); - } - - S32 unref() - { - llassert(mRef >= 1); - if (sMutex) sMutex->lock(); - S32 res = --mRef; - if (sMutex) sMutex->unlock(); - if (0 == res) - { - delete this; - return 0; - } - return res; - } - S32 getNumRefs() const - { - return mRef; - } - -private: - S32 mRef; -}; - -//============================================================================ - -// Simple responder for self destructing callbacks -// Pure virtual class -class LL_COMMON_API LLResponder : public LLThreadSafeRefCount -{ -protected: - virtual ~LLResponder(); -public: - virtual void completed(bool success) = 0; -}; - -//============================================================================ - #endif // LL_LLTHREAD_H |