From d122ff8d435f960fec9de4d247adeba418c677c3 Mon Sep 17 00:00:00 2001 From: Nicky Date: Sun, 8 Apr 2018 18:26:48 +0200 Subject: [PATCH] Use LLCondition rather than LLMutex. Then we can conveniently .wait() in popBack rather then having to use a poll loop./ --- indra/llcommon/llthreadsafequeue.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/indra/llcommon/llthreadsafequeue.h b/indra/llcommon/llthreadsafequeue.h index 01109b2b27..c59a29e3b4 100644 --- a/indra/llcommon/llthreadsafequeue.h +++ b/indra/llcommon/llthreadsafequeue.h @@ -104,7 +104,7 @@ public: private: std::deque< ElementT > mStorage; - LLMutex mLock; + LLCondition mLock;; U32 mCapacity; // Really needed? }; @@ -132,6 +132,7 @@ void LLThreadSafeQueue::pushFront(ElementT const & element) if( mStorage.size() < mCapacity ) { mStorage.push_front( element ); + mLock.signal(); return; } } @@ -151,6 +152,7 @@ bool LLThreadSafeQueue::tryPushFront(ElementT const & element) return false; mStorage.push_front( element ); + mLock.signal(); return true; } @@ -160,16 +162,13 @@ ElementT LLThreadSafeQueue::popBack(void) { while( true ) { + mLock.wait(); + if( !mStorage.empty() ) { - LLMutexLock lck( &mLock ); - if( !mStorage.empty() ) - { - ElementT value = mStorage.back(); - mStorage.pop_back(); - return value; - } + ElementT value = mStorage.back(); + mStorage.pop_back(); + return value; } - ms_sleep( 100 ); } }