21 #include <condition_variable>
34 mForegroundQueue(&mQueueAlpha),
35 mBackgroundQueue(&mQueueBeta)
41 std::unique_lock<std::mutex> fgGuard(mForegroundMutex);
42 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
45 std::queue<T>().swap(*mForegroundQueue);
47 auto* swap = mBackgroundQueue;
48 mBackgroundQueue = mForegroundQueue;
49 mForegroundQueue = swap;
55 std::unique_lock<std::mutex> guard(mBackgroundMutex);
56 mBackgroundQueue->push(item);
63 std::unique_lock<std::mutex> guard(mForegroundMutex);
64 return mForegroundQueue->front();
69 std::unique_lock<std::mutex> guard(mForegroundMutex);
70 return mForegroundQueue->front();
76 std::unique_lock<std::mutex> guard(mForegroundMutex);
77 mForegroundQueue->pop();
83 std::unique_lock<std::mutex> guard(mForegroundMutex);
84 return mForegroundQueue->empty();
90 std::unique_lock<std::mutex> guard(mForegroundMutex);
91 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
92 return mForegroundQueue->empty() && mBackgroundQueue->empty();
98 std::unique_lock<std::mutex> guard(mForegroundMutex);
99 return mForegroundQueue->size();
105 std::unique_lock<std::mutex> fgGuard(mForegroundMutex);
106 std::unique_lock<std::mutex> bgGuard(mBackgroundMutex);
107 std::queue<T>().swap(*mForegroundQueue);
108 std::queue<T>().swap(*mBackgroundQueue);
113 std::queue<T> mQueueAlpha;
114 std::queue<T> mQueueBeta;
117 std::queue<T>* mForegroundQueue;
118 std::queue<T>* mBackgroundQueue;
120 mutable std::mutex mForegroundMutex;
121 mutable std::mutex mBackgroundMutex;
Double buffered, threadsafe queue for MPSC (multi-producer, single-consumer) comms.
Definition: DBQueue.h:30
void Swap()
Clears foreground queue and swaps queues.
Definition: DBQueue.h:39
DBQueue()
Definition: DBQueue.h:33
size_t Size() const
Reports the size of the foreground queue.
Definition: DBQueue.h:96
void Pop()
Pops from the foreground queue.
Definition: DBQueue.h:74
T & Front()
Returns a reference to the front element in the foregrund queue.
Definition: DBQueue.h:61
void Push(const T &item)
Pushes to the background queue.
Definition: DBQueue.h:53
void Clear()
Clears foreground and background.
Definition: DBQueue.h:103
bool Empty() const
Reports whether the foreground queue is empty.
Definition: DBQueue.h:81
bool BothEmpty() const
Reports whether the both queues are empty.
Definition: DBQueue.h:88
const T & Front() const
Definition: DBQueue.h:67
eProsima namespace.
Definition: LibrarySettingsAttributes.h:23