summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2019-11-14 16:40:51 -0500
committerNat Goodspeed <nat@lindenlab.com>2020-03-25 19:07:22 -0400
commitaf353911147b338359b3ab659bfb271e6c9a6383 (patch)
tree45348901f9ec6ab1bbd23eae8e2e4fd573682ba1
parentb461b5dcefb753c908af5c62fb21049dc9f594b8 (diff)
DRTVWR-476: Make LLThreadSafeQueue coroutine-safe as well.
-rw-r--r--indra/llcommon/llthreadsafequeue.h20
1 files changed, 9 insertions, 11 deletions
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 <deque>
#include <string>
#include "mutex.h"
-#include <condition_variable>
+#include <boost/fiber/condition_variable.hpp>
//
// 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<typename ElementT>
void LLThreadSafeQueue<ElementT>::pushFront(ElementT const & element)
{
+ std::unique_lock<decltype(mLock)> lock1(mLock);
while (true)
{
- std::unique_lock<std::mutex> lock1(mLock);
-
if (mStorage.size() < mCapacity)
{
mStorage.push_front(element);
@@ -142,7 +141,7 @@ void LLThreadSafeQueue<ElementT>::pushFront(ElementT const & element)
template<typename ElementT>
bool LLThreadSafeQueue<ElementT>::tryPushFront(ElementT const & element)
{
- std::unique_lock<std::mutex> lock1(mLock, std::defer_lock);
+ std::unique_lock<decltype(mLock)> lock1(mLock, std::defer_lock);
if (!lock1.try_lock())
return false;
@@ -158,10 +157,9 @@ bool LLThreadSafeQueue<ElementT>::tryPushFront(ElementT const & element)
template<typename ElementT>
ElementT LLThreadSafeQueue<ElementT>::popBack(void)
{
+ std::unique_lock<decltype(mLock)> lock1(mLock);
while (true)
{
- std::unique_lock<std::mutex> lock1(mLock);
-
if (!mStorage.empty())
{
ElementT value = mStorage.back();
@@ -179,7 +177,7 @@ ElementT LLThreadSafeQueue<ElementT>::popBack(void)
template<typename ElementT>
bool LLThreadSafeQueue<ElementT>::tryPopBack(ElementT & element)
{
- std::unique_lock<std::mutex> lock1(mLock, std::defer_lock);
+ std::unique_lock<decltype(mLock)> lock1(mLock, std::defer_lock);
if (!lock1.try_lock())
return false;
@@ -196,7 +194,7 @@ bool LLThreadSafeQueue<ElementT>::tryPopBack(ElementT & element)
template<typename ElementT>
size_t LLThreadSafeQueue<ElementT>::size(void)
{
- std::lock_guard<std::mutex> lock(mLock);
+ std::lock_guard<decltype(mLock)> lock(mLock);
return mStorage.size();
}