diff --git a/indra/llcommon/llapr.cpp b/indra/llcommon/llapr.cpp index a548c96002413ebfaa943a93049a547b2061a4c0..75aea0229b11ab58206374e9785603a0bb67c741 100755 --- a/indra/llcommon/llapr.cpp +++ b/indra/llcommon/llapr.cpp @@ -30,6 +30,7 @@ #include "llapr.h" #include "apr_dso.h" #include "llthreadlocalstorage.h" +#include "llmutex.h" apr_pool_t *gAPRPoolp = NULL; // Global APR memory pool LLVolatileAPRPool *LLAPRFile::sAPRFilePoolp = NULL ; //global volatile APR memory pool. @@ -169,25 +170,18 @@ LLVolatileAPRPool::LLVolatileAPRPool(BOOL is_local, apr_pool_t *parent, apr_size : LLAPRPool(parent, size, releasePoolFlag), mNumActiveRef(0), mNumTotalRef(0), - mMutexPool(NULL), mMutexp(NULL) { //create mutex if(!is_local) //not a local apr_pool, that is: shared by multiple threads. { - apr_pool_create(&mMutexPool, NULL); // Create a pool for mutex - apr_thread_mutex_create(&mMutexp, APR_THREAD_MUTEX_UNNESTED, mMutexPool); + mMutexp = new LLMutex(); } } LLVolatileAPRPool::~LLVolatileAPRPool() { - //delete mutex - if(mMutexp) - { - apr_thread_mutex_destroy(mMutexp); - apr_pool_destroy(mMutexPool); - } + delete_and_clear(mMutexp); } // @@ -201,7 +195,7 @@ apr_pool_t* LLVolatileAPRPool::getAPRPool() apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool() { - LLScopedLock lock(mMutexp) ; + LLMutexLock lock(mMutexp); mNumTotalRef++ ; mNumActiveRef++ ; @@ -216,7 +210,7 @@ apr_pool_t* LLVolatileAPRPool::getVolatileAPRPool() void LLVolatileAPRPool::clearVolatileAPRPool() { - LLScopedLock lock(mMutexp) ; + LLMutexLock lock(mMutexp) ; if(mNumActiveRef > 0) { @@ -250,44 +244,6 @@ BOOL LLVolatileAPRPool::isFull() { return mNumTotalRef > FULL_VOLATILE_APR_POOL ; } -//--------------------------------------------------------------------- -// -// LLScopedLock -// -LLScopedLock::LLScopedLock(apr_thread_mutex_t* mutex) : mMutex(mutex) -{ - if(mutex) - { - if(ll_apr_warn_status(apr_thread_mutex_lock(mMutex))) - { - mLocked = false; - } - else - { - mLocked = true; - } - } - else - { - mLocked = false; - } -} - -LLScopedLock::~LLScopedLock() -{ - unlock(); -} - -void LLScopedLock::unlock() -{ - if(mLocked) - { - if(!ll_apr_warn_status(apr_thread_mutex_unlock(mMutex))) - { - mLocked = false; - } - } -} //--------------------------------------------------------------------- diff --git a/indra/llcommon/llapr.h b/indra/llcommon/llapr.h index d8000d787e539450adf417f46fcb2410f95eb92f..8c3ea39db94bc6198579f2a196c43758143f3266 100755 --- a/indra/llcommon/llapr.h +++ b/indra/llcommon/llapr.h @@ -42,6 +42,8 @@ #include "llstring.h" +class LLMutex; + extern LL_COMMON_API apr_thread_mutex_t* gLogMutexp; extern apr_thread_mutex_t* gCallStacksLogMutexp; @@ -120,50 +122,9 @@ private: S32 mNumActiveRef ; //number of active pointers pointing to the apr_pool. S32 mNumTotalRef ; //number of total pointers pointing to the apr_pool since last creating. - apr_thread_mutex_t *mMutexp; - apr_pool_t *mMutexPool; + LLMutex* mMutexp; } ; -/** - * @class LLScopedLock - * @brief Small class to help lock and unlock mutexes. - * - * This class is used to have a stack level lock once you already have - * an apr mutex handy. The constructor handles the lock, and the - * destructor handles the unlock. Instances of this class are - * <b>not</b> thread safe. - */ -class LL_COMMON_API LLScopedLock : private boost::noncopyable -{ -public: - /** - * @brief Constructor which accepts a mutex, and locks it. - * - * @param mutex An allocated APR mutex. If you pass in NULL, - * this wrapper will not lock. - */ - LLScopedLock(apr_thread_mutex_t* mutex); - - /** - * @brief Destructor which unlocks the mutex if still locked. - */ - ~LLScopedLock(); - - /** - * @brief Check lock. - */ - bool isLocked() const { return mLocked; } - - /** - * @brief This method unlocks the mutex. - */ - void unlock(); - -protected: - bool mLocked; - apr_thread_mutex_t* mMutex; -}; - // File IO convenience functions. // Returns NULL if the file fails to open, sets *sizep to file size if not NULL // abbreviated flags diff --git a/indra/llmessage/llpumpio.cpp b/indra/llmessage/llpumpio.cpp index 506ccc98a4b315ab0baab35b394d8f524779a779..2885ed99d222920464b542ea91ac60707a97228f 100755 --- a/indra/llmessage/llpumpio.cpp +++ b/indra/llmessage/llpumpio.cpp @@ -54,7 +54,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; @@ -169,8 +169,10 @@ LLPumpIO::LLPumpIO(apr_pool_t* pool) : mPool(NULL), mCurrentPool(NULL), mCurrentPoolReallocCount(0), +#if LL_THREADS_PUMPIO mChainsMutex(NULL), mCallbackMutex(NULL), +#endif mCurrentChain(mRunningChains.end()) { mCurrentChain = mRunningChains.end(); @@ -194,8 +196,8 @@ bool LLPumpIO::addChain(const chain_t& chain, F32 timeout, bool has_curl_request { if(chain.empty()) return false; -#if LL_THREADS_APR - LLScopedLock lock(mChainsMutex); +#if LL_THREADS_PUMPIO + LLMutexLock lock(mChainsMutex); #endif LLChainInfo info; info.mHasCurlRequest = has_curl_request; @@ -234,8 +236,8 @@ bool LLPumpIO::addChain( if(!data) return false; if(links.empty()) return false; -#if LL_THREADS_APR - LLScopedLock lock(mChainsMutex); +#if LL_THREADS_PUMPIO + LLMutexLock lock(mChainsMutex); #endif #if LL_DEBUG_PIPE_TYPE_IN_PUMP LL_DEBUGS() << "LLPumpIO::addChain() " << links[0].mPipe << " '" @@ -391,8 +393,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); } @@ -457,8 +459,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) @@ -726,8 +728,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; @@ -740,8 +742,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; @@ -761,8 +763,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 @@ -781,8 +783,8 @@ void LLPumpIO::callback() //LL_INFOS() << "LLPumpIO::callback()" << LL_ENDL; if(true) { -#if LL_THREADS_APR - LLScopedLock lock(mCallbackMutex); +#if LL_THREADS_PUMPIO + LLMutexLock lock(mCallbackMutex); #endif std::copy( mPendingCallbacks.begin(), @@ -809,8 +811,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) { @@ -829,22 +831,19 @@ void LLPumpIO::control(LLPumpIO::EControl op) void LLPumpIO::initialize(apr_pool_t* pool) { if(!pool) return; -#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, pool); - apr_thread_mutex_create(&mCallbackMutex, APR_THREAD_MUTEX_UNNESTED, pool); +#if LL_THREADS_PUMPIO + mChainsMutex = new LLMutex(pool); + mCallbackMutex = new LLMutex(pool); #endif mPool = pool; } void LLPumpIO::cleanup() { -#if LL_THREADS_APR - if(mChainsMutex) apr_thread_mutex_destroy(mChainsMutex); - if(mCallbackMutex) apr_thread_mutex_destroy(mCallbackMutex); +#if LL_THREADS_PUMPIO + delete_and_clear(mChainsMutex); + delete_and_clear(mCallbackMutex); #endif - mChainsMutex = NULL; - mCallbackMutex = NULL; if(mPollset) { // LL_DEBUGS() << "cleaning up pollset" << LL_ENDL; diff --git a/indra/llmessage/llpumpio.h b/indra/llmessage/llpumpio.h index d2c5d3757136e57caaba21b02a01d812090c3e0f..0b783f5db7c1dc3ede99fb7bf63f7ff781163e19 100755 --- a/indra/llmessage/llpumpio.h +++ b/indra/llmessage/llpumpio.h @@ -41,7 +41,7 @@ #include "llrun.h" // Define this to enable use with the APR thread library. -//#define LL_THREADS_APR 1 +//#define LL_THREADS_PUMPIO 1 // some simple constants to help with timeouts extern const F32 DEFAULT_CHAIN_EXPIRY_SECS; @@ -393,12 +393,9 @@ protected: apr_pool_t* mCurrentPool; S32 mCurrentPoolReallocCount; -#if LL_THREADS_APR - apr_thread_mutex_t* mChainsMutex; - apr_thread_mutex_t* mCallbackMutex; -#else - int* mChainsMutex; - int* mCallbackMutex; +#if LL_THREADS_PUMPIO + LLMutex* mChainsMutex; + LLMutex* mCallbackMutex; #endif protected: