21#include <condition_variable>
36 : mForegroundQueue(&mQueueAlpha)
37 , mBackgroundQueue(&mQueueBeta)
44 std::unique_lock<std::mutex> fgGuard(mForegroundMutex);
45 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
48 std::queue<T>().swap(*mForegroundQueue);
50 auto*
swap = mBackgroundQueue;
51 mBackgroundQueue = mForegroundQueue;
52 mForegroundQueue =
swap;
59 std::unique_lock<std::mutex> guard(mBackgroundMutex);
60 mBackgroundQueue->push(item);
67 std::unique_lock<std::mutex> guard(mBackgroundMutex);
68 mBackgroundQueue->push(std::move(item));
75 std::unique_lock<std::mutex> guard(mForegroundMutex);
76 return mForegroundQueue->front();
81 std::unique_lock<std::mutex> guard(mForegroundMutex);
82 return mForegroundQueue->front();
88 std::unique_lock<std::mutex> guard(mForegroundMutex);
89 mForegroundQueue->pop();
95 std::unique_lock<std::mutex> guard(mForegroundMutex);
98 T value = std::move(mForegroundQueue->front());
102 mForegroundQueue->pop();
111 std::unique_lock<std::mutex> guard(mForegroundMutex);
112 return mForegroundQueue->empty();
118 std::unique_lock<std::mutex> guard(mForegroundMutex);
119 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
120 return mForegroundQueue->empty() && mBackgroundQueue->empty();
126 std::unique_lock<std::mutex> guard(mForegroundMutex);
127 return mForegroundQueue->size();
133 std::unique_lock<std::mutex> fgGuard(mForegroundMutex);
134 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
135 std::queue<T>().swap(*mForegroundQueue);
136 std::queue<T>().swap(*mBackgroundQueue);
142 std::queue<T> mQueueAlpha;
143 std::queue<T> mQueueBeta;
146 std::queue<T>* mForegroundQueue;
147 std::queue<T>* mBackgroundQueue;
149 mutable std::mutex mForegroundMutex;
150 mutable std::mutex mBackgroundMutex;
Double buffered, threadsafe queue for MPSC (multi-producer, single-consumer) comms.
Definition DBQueue.h:31
void Swap()
Clears foreground queue and swaps queues.
Definition DBQueue.h:42
void Push(T &&item)
Pushes to the background queue. Move constructor.
Definition DBQueue.h:64
DBQueue()
Definition DBQueue.h:35
size_t Size() const
Reports the size of the foreground queue.
Definition DBQueue.h:124
void Pop()
Pops from the foreground queue.
Definition DBQueue.h:86
void Push(const T &item)
Pushes to the background queue. Copy constructor.
Definition DBQueue.h:56
void Clear()
Clears foreground and background.
Definition DBQueue.h:131
bool Empty() const
Reports whether the foreground queue is empty.
Definition DBQueue.h:109
const T & Front() const
Definition DBQueue.h:79
T FrontAndPop()
Return the front element in the foreground queue by moving it and erase it from the queue.
Definition DBQueue.h:93
bool BothEmpty() const
Reports whether the both queues are empty.
Definition DBQueue.h:116
T & Front()
Returns a reference to the front element in the foregrund queue.
Definition DBQueue.h:73
eProsima namespace.
Definition LibrarySettingsAttributes.h:23
void swap(shared_lock< Mutex > &x, shared_lock< Mutex > &y)
Definition shared_mutex.hpp:551