From af353911147b338359b3ab659bfb271e6c9a6383 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 14 Nov 2019 16:40:51 -0500 Subject: DRTVWR-476: Make LLThreadSafeQueue coroutine-safe as well. --- indra/llcommon/llthreadsafequeue.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'indra/llcommon') diff --git a/indra/llcommon/llthreadsafequeue.h b/indra/llcommon/llthreadsafequeue.h index 2cee7a3141..3f49dbccc2 100644 --- a/indra/llcommon/llthreadsafequeue.h +++ b/indra/llcommon/llthreadsafequeue.h @@ -31,7 +31,7 @@ #include #include #include "mutex.h" -#include +#include // // A general queue exception. @@ -104,9 +104,9 @@ private: std::deque< ElementT > mStorage; U32 mCapacity; - std::mutex mLock; - std::condition_variable mCapacityCond; - std::condition_variable mEmptyCond; + boost::fibers::mutex mLock; + boost::fibers::condition_variable mCapacityCond; + boost::fibers::condition_variable mEmptyCond; }; // LLThreadSafeQueue @@ -122,10 +122,9 @@ mCapacity(capacity) template void LLThreadSafeQueue::pushFront(ElementT const & element) { + std::unique_lock lock1(mLock); while (true) { - std::unique_lock lock1(mLock); - if (mStorage.size() < mCapacity) { mStorage.push_front(element); @@ -142,7 +141,7 @@ void LLThreadSafeQueue::pushFront(ElementT const & element) template bool LLThreadSafeQueue::tryPushFront(ElementT const & element) { - std::unique_lock lock1(mLock, std::defer_lock); + std::unique_lock lock1(mLock, std::defer_lock); if (!lock1.try_lock()) return false; @@ -158,10 +157,9 @@ bool LLThreadSafeQueue::tryPushFront(ElementT const & element) template ElementT LLThreadSafeQueue::popBack(void) { + std::unique_lock lock1(mLock); while (true) { - std::unique_lock lock1(mLock); - if (!mStorage.empty()) { ElementT value = mStorage.back(); @@ -179,7 +177,7 @@ ElementT LLThreadSafeQueue::popBack(void) template bool LLThreadSafeQueue::tryPopBack(ElementT & element) { - std::unique_lock lock1(mLock, std::defer_lock); + std::unique_lock lock1(mLock, std::defer_lock); if (!lock1.try_lock()) return false; @@ -196,7 +194,7 @@ bool LLThreadSafeQueue::tryPopBack(ElementT & element) template size_t LLThreadSafeQueue::size(void) { - std::lock_guard lock(mLock); + std::lock_guard lock(mLock); return mStorage.size(); } -- cgit v1.2.3