summaryrefslogtreecommitdiff
path: root/indra/llcommon/llapr.cpp
diff options
context:
space:
mode:
authorRichard Linden <none@none>2012-09-24 18:56:01 -0700
committerRichard Linden <none@none>2012-09-24 18:56:01 -0700
commitadeeabfc13c91dc99a1ea1949cd2f820c4150995 (patch)
tree641a7bcfe966c1994f1461a1672e7a5193023ff8 /indra/llcommon/llapr.cpp
parent735fde8c742188d019e41faf26ff67aab6a24d25 (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.cpp82
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
//