18#ifndef TRINITYCORE_LOCKED_QUEUE_H
19#define TRINITYCORE_LOCKED_QUEUE_H
25template <
class T,
typename StorageType = std::deque<T>>
40 void add(T
const& item)
42 std::scoped_lock lock(
_lock);
49 std::scoped_lock lock(
_lock);
50 _queue.push_back(std::move(item));
54 template<std::input_iterator Iterator>
55 void readd(Iterator begin, Iterator end)
57 std::scoped_lock lock(
_lock);
64 std::scoped_lock lock(
_lock);
68 result = std::move(
_queue.front());
73 template<
class Checker>
74 bool next(T& result, Checker& check)
76 std::scoped_lock lock(
_lock);
80 decltype(
auto) front =
_queue.front();
81 if (!check.Process(front))
84 result = std::move(front);
92 std::scoped_lock lock(
_lock);
99 std::scoped_lock lock(
_lock);
106 std::scoped_lock lock(
_lock);
113 std::scoped_lock lock(
_lock);
bool _canceled
Cancellation flag.
void add(T const &item)
Adds an item to the queue.
void readd(Iterator begin, Iterator end)
Adds items back to front of the queue.
StorageType _queue
Storage backing the queue.
std::mutex _lock
Lock access to the queue.
bool cancelled()
Checks if the queue is cancelled.
bool empty()
! Checks if we're empty or not with locks held
void add(T &&item)
Adds an item to the queue.
void pop_front()
! Calls pop_front of the queue
void cancel()
Cancels the queue.
bool next(T &result)
Gets the next result in the queue, if any.
bool next(T &result, Checker &check)