27 #ifndef CONCURRENTQUEUE 28 #define CONCURRENTQUEUE 34 #include <boost/throw_exception.hpp> 123 std::lock_guard<std::mutex> lock{m_mutex};
124 return m_queue.size();
132 std::lock_guard<std::mutex> lock{m_mutex};
133 return m_queue.empty();
150 std::lock_guard<std::mutex> lock{m_mutex};
151 m_queue.emplace_back(std::move(item));
154 m_itemEvent.Signal();
170 std::lock_guard<std::mutex> lock{m_mutex};
171 m_queue.emplace_back(item);
174 m_itemEvent.Signal();
184 m_itemEvent.Signal();
215 BOOST_THROW_EXCEPTION(std::runtime_error(
"no item to pop"));
238 BOOST_THROW_EXCEPTION(std::runtime_error(
"no item to pop"));
247 bool TimedPop(
unsigned int timeoutMilliseconds, T& item)
249 bool popSuccess{
false};
251 if (m_itemEvent.WaitForTime(timeoutMilliseconds))
253 popSuccess = PopNow(item);
268 if (!m_itemEvent.WaitForTime(timeoutMilliseconds))
270 BOOST_THROW_EXCEPTION(std::runtime_error(
"item event timed out"));
275 BOOST_THROW_EXCEPTION(std::runtime_error(
"no item to pop"));
285 return PopNow(item, eQueueEnd::back);
296 if (!PopNow(item, eQueueEnd::back))
298 BOOST_THROW_EXCEPTION(std::runtime_error(
"no item to pop"));
311 const T*
Peek(
size_t index)
const 314 std::lock_guard<std::mutex> lock{m_mutex};
316 if (!m_queue.empty() && (index < m_queue.size()))
318 pItem = &m_queue[index];
336 std::lock_guard<std::mutex> lock{m_mutex};
355 template <
typename F>
void Clear(F deleter)
357 std::lock_guard<std::mutex> lock{m_mutex};
359 for (
auto& qi : m_queue)
384 std::lock_guard<std::mutex> lock{m_mutex};
408 std::lock_guard<std::mutex> lock{m_mutex};
409 auto isEmpty = m_queue.empty();
413 if (whichEnd == eQueueEnd::front)
437 item = std::move(m_queue.front());
447 item = std::move(m_queue.back());
456 eNotifyType::signalOneThread, eResetCondition::manualReset, eIntialCondition::notSignalled};
464 #endif // CONCURRENTQUEUE eQueueEnd
Enumeration controlling end of queue to pop from.
Definition: ConcurrentQueue.h:393
bool TimedPop(unsigned int timeoutMilliseconds, T &item)
Pop an item off the queue but only wait for a given amount of time.
Definition: ConcurrentQueue.h:247
void Push(T &&item)
Push an item onto the queue.
Definition: ConcurrentQueue.h:147
const T * Peek(size_t index) const
Take a peek at an item at a given index on the queue.
Definition: ConcurrentQueue.h:311
void TimedPopThrow(unsigned int timeoutMilliseconds, T &item)
Pop an item off the queue but only wait for a given amount of time.
Definition: ConcurrentQueue.h:266
size_t Size() const
Size of the queue.
Definition: ConcurrentQueue.h:121
bool Pop(T &item)
Pop an item off the queue if there are any else wait.
Definition: ConcurrentQueue.h:194
Class defining a thread synchronisation event.
Definition: SyncEvent.h:70
void PopThrow(T &item)
Pop an item off the queue if there are any else wait.
Definition: ConcurrentQueue.h:209
container_type TakeAll()
Take all items from the queue and return them, thus clearing down the internal queue.
Definition: ConcurrentQueue.h:379
void BreakPopWait()
Break out of waiting on a Pop method.
Definition: ConcurrentQueue.h:182
void Clear()
Clear the queue.
Definition: ConcurrentQueue.h:334
void TryPopThrow(T &item)
Pop an item off the queue.
Definition: ConcurrentQueue.h:234
The core_lib namespace.
Definition: AsioDefines.h:59
std::mutex m_mutex
Synchronization mutex.
Definition: ConcurrentQueue.h:453
void Clear(F deleter)
Clear the queue.
Definition: ConcurrentQueue.h:355
void operator()(P *p) const
Function operator.
Definition: ConcurrentQueue.h:55
bool TrySteal(T &item)
Steal an item from the back of the queue if there are any else return.
Definition: ConcurrentQueue.h:283
bool PopNow(T &item, eQueueEnd whichEnd=eQueueEnd::front)
Pop an item off the queue.
Definition: ConcurrentQueue.h:406
void PopBack(T &item)
Pop an item off the back of the queue.
Definition: ConcurrentQueue.h:445
void operator()(P *p) const
Function operator.
Definition: ConcurrentQueue.h:72
bool Empty() const
Is the queue empty.
Definition: ConcurrentQueue.h:130
File containing declaration of SyncEvent class.
void PopFront(T &item)
Pop an item off the front of the queue.
Definition: ConcurrentQueue.h:435
void Push(const T &item)
Push an item onto the queue.
Definition: ConcurrentQueue.h:167
Single item deleter for queue item.
Definition: ConcurrentQueue.h:49
Class defining a concurrent queue.
Definition: ConcurrentQueue.h:93
std::deque< MessageType > container_type
Typedef for container type.
Definition: ConcurrentQueue.h:367
Array deleter for queue item.
Definition: ConcurrentQueue.h:66
void TryStealThrow(T &item)
Steal an item from the back of the queue.
Definition: ConcurrentQueue.h:294
bool TryPop(T &item)
Pop an item off the queue if there are any else return.
Definition: ConcurrentQueue.h:223