Implement boost and stl mutexes and atomics.

This commit is contained in:
Shyotl
2014-09-07 17:18:55 -05:00
parent aeeca6e2c0
commit 37c7a72505
22 changed files with 583 additions and 483 deletions

View File

@@ -56,7 +56,7 @@
// constants for poll timeout. if we are threading, we want to have a
// longer poll timeout.
#if LL_THREADS_APR
#if LL_THREADS_PUMPIO
static const S32 DEFAULT_POLL_TIMEOUT = 1000;
#else
static const S32 DEFAULT_POLL_TIMEOUT = 0;
@@ -168,24 +168,21 @@ LLPumpIO::LLPumpIO(void) :
mPollset(NULL),
mPollsetClientID(0),
mNextLock(0),
#if LL_THREADS_PUMPIO
mPool(),
LLMutex mChainsMutex(initPool()),
LLMutex mCallbackMutex(initPool()),
#endif
mCurrentPoolReallocCount(0),
mChainsMutex(NULL),
mCallbackMutex(NULL),
mCurrentChain(mRunningChains.end())
{
mCurrentChain = mRunningChains.end();
initialize();
#if !LL_THREADS_PUMPIO
initPool();
#endif
}
LLPumpIO::~LLPumpIO()
{
#if LL_THREADS_APR
if (mChainsMutex) apr_thread_mutex_destroy(mChainsMutex);
if (mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex);
#endif
mChainsMutex = NULL;
mCallbackMutex = NULL;
if(mPollset)
{
// lldebugs << "cleaning up pollset" << llendl;
@@ -218,8 +215,8 @@ bool LLPumpIO::addChain(chain_t const& chain, F32 timeout)
info.mChainLinks.push_back(link);
}
#if LL_THREADS_APR
LLScopedLock lock(mChainsMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mChainsMutex);
#endif
mPendingChains.push_back(info);
return true;
@@ -258,8 +255,8 @@ bool LLPumpIO::addChain(
break;
}
}
#if LL_THREADS_APR
LLScopedLock lock(mChainsMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mChainsMutex);
#endif
mPendingChains.push_back(info);
return true;
@@ -403,8 +400,8 @@ void LLPumpIO::clearLock(S32 key)
// therefore won't be treading into deleted memory. I think we can
// also clear the lock on the chain safely since the pump only
// reads that value.
#if LL_THREADS_APR
LLScopedLock lock(mChainsMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mChainsMutex);
#endif
mClearLocks.insert(key);
}
@@ -469,8 +466,8 @@ void LLPumpIO::pump(const S32& poll_timeout)
PUMP_DEBUG;
if(true)
{
#if LL_THREADS_APR
LLScopedLock lock(mChainsMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mChainsMutex);
#endif
// bail if this pump is paused.
if(PAUSING == mState)
@@ -738,8 +735,8 @@ void LLPumpIO::pump(const S32& poll_timeout)
//bool LLPumpIO::respond(const chain_t& pipes)
//{
//#if LL_THREADS_APR
// LLScopedLock lock(mCallbackMutex);
//#if LL_THREADS_PUMPIO
// LLMutexLock lock(mCallbackMutex);
//#endif
// LLChainInfo info;
// links_t links;
@@ -752,8 +749,8 @@ bool LLPumpIO::respond(LLIOPipe* pipe)
{
if(NULL == pipe) return false;
#if LL_THREADS_APR
LLScopedLock lock(mCallbackMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mCallbackMutex);
#endif
LLChainInfo info;
LLLinkInfo link;
@@ -773,8 +770,8 @@ bool LLPumpIO::respond(
if(!data) return false;
if(links.empty()) return false;
#if LL_THREADS_APR
LLScopedLock lock(mCallbackMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mCallbackMutex);
#endif
// Add the callback response
@@ -793,8 +790,8 @@ void LLPumpIO::callback()
//llinfos << "LLPumpIO::callback()" << llendl;
if(true)
{
#if LL_THREADS_APR
LLScopedLock lock(mCallbackMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mCallbackMutex);
#endif
std::copy(
mPendingCallbacks.begin(),
@@ -821,8 +818,8 @@ void LLPumpIO::callback()
void LLPumpIO::control(LLPumpIO::EControl op)
{
#if LL_THREADS_APR
LLScopedLock lock(mChainsMutex);
#if LL_THREADS_PUMPIO
LLMutexLock lock(mChainsMutex);
#endif
switch(op)
{
@@ -838,14 +835,11 @@ void LLPumpIO::control(LLPumpIO::EControl op)
}
}
void LLPumpIO::initialize(void)
LLAPRPool& LLPumpIO::initPool()
{
mPool.create();
#if LL_THREADS_APR
// SJB: Windows defaults to NESTED and OSX defaults to UNNESTED, so use UNNESTED explicitly.
apr_thread_mutex_create(&mChainsMutex, APR_THREAD_MUTEX_UNNESTED, mPool());
apr_thread_mutex_create(&mCallbackMutex, APR_THREAD_MUTEX_UNNESTED, mPool());
#endif
if (!mPool)
mPool.create();
return mPool;
}
void LLPumpIO::rebuildPollset()