diff options
author | Richard Linden <none@none> | 2012-09-24 18:56:01 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2012-09-24 18:56:01 -0700 |
commit | adeeabfc13c91dc99a1ea1949cd2f820c4150995 (patch) | |
tree | 641a7bcfe966c1994f1461a1672e7a5193023ff8 /indra/llcommon/llapr.cpp | |
parent | 735fde8c742188d019e41faf26ff67aab6a24d25 (diff) |
SH-3275 WIP Run viewer metrics for object update messages
moved LLThreadLocalPtr to llapr
fixed various startup race conditions for LLThreadLocalPtr
Diffstat (limited to 'indra/llcommon/llapr.cpp')
-rw-r--r-- | indra/llcommon/llapr.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index d1c44c9403..76749f8a91 100644 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -54,6 +54,8 @@ void ll_init_apr() { LLAPRFile::sAPRFilePoolp = new LLVolatileAPRPool(FALSE) ; } + + LLThreadLocalPtrBase::initAllThreadLocalStorage(); } @@ -477,6 +479,86 @@ S32 LLAPRFile::seek(apr_seek_where_t where, S32 offset) } // +//LLThreadLocalPtrBase +// +bool LLThreadLocalPtrBase::sInitialized = false; + +LLThreadLocalPtrBase::LLThreadLocalPtrBase(void (*cleanup_func)(void*)) +: mCleanupFunc(cleanup_func), + mThreadKey(NULL) +{ + if (sInitialized) + { + initStorage(); + } +} + +LLThreadLocalPtrBase::LLThreadLocalPtrBase( const LLThreadLocalPtrBase& other) +: mCleanupFunc(other.mCleanupFunc), + mThreadKey(NULL) +{ + if (sInitialized) + { + initStorage(); + } +} + +LLThreadLocalPtrBase::~LLThreadLocalPtrBase() +{ + destroyStorage(); +} + +void LLThreadLocalPtrBase::set( void* value ) +{ + llassert(sInitialized && mThreadKey); + + apr_status_t result = apr_threadkey_private_set((void*)value, mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to set thread local data" << llendl; + } +} + +void LLThreadLocalPtrBase::initStorage( ) +{ + apr_status_t result = apr_threadkey_private_create(&mThreadKey, mCleanupFunc, gAPRPoolp); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to allocate thread local data" << llendl; + } +} + +void LLThreadLocalPtrBase::destroyStorage() +{ + if (mThreadKey) + { + apr_status_t result = apr_threadkey_private_delete(mThreadKey); + if (result != APR_SUCCESS) + { + ll_apr_warn_status(result); + llerrs << "Failed to delete thread local data" << llendl; + } + } +} + +void LLThreadLocalPtrBase::initAllThreadLocalStorage() +{ + if (!sInitialized) + { + sInitialized = true; + for (LLInstanceTracker<LLThreadLocalPtrBase>::instance_iter it = beginInstances(), end_it = endInstances(); + it != end_it; + ++it) + { + (*it).initStorage(); + } + } +} + + +// //******************************************************************************************************************************* //static components of LLAPRFile // |