15 template<
typename T,
typename Container = std::deque<T>>
18 std::queue<T, Container> m_queue{};
25 template<
typename... Args>
29 std::scoped_lock lck{other.m_mutex};
30 m_queue = other.m_queue;
34 std::scoped_lock lck{other.m_mutex};
35 m_queue = std::move(other.m_queue);
39 std::scoped_lock lck{other.m_mutex, m_mutex};
40 m_queue = other.m_queue;
47 std::scoped_lock lck{other.m_mutex, m_mutex};
48 m_queue = std::move(other.m_queue);
57 std::optional<T>
pop() {
58 std::scoped_lock lck{m_mutex};
59 if (m_queue.empty())
return std::nullopt;
60 auto entry = std::move(m_queue.front());
70 std::scoped_lock lck{m_mutex};
71 m_queue.push(std::move(val));
78 template<
typename... Args>
80 std::scoped_lock lck{m_mutex};
81 m_queue.emplace(std::forward<Args>(args)...);
A threadsafe (mutex protected) queue.
Definition threadsafe_queue.h:16
void emplace(Args &&... args)
Emplace a new element to the queue.
Definition threadsafe_queue.h:79
void push(T val)
Push an element to the queue.
Definition threadsafe_queue.h:69
std::optional< T > pop()
Pop the first element from the queue.
Definition threadsafe_queue.h:57
threadsafe_queue(Args &&... args)
Construct a new queue.
Definition threadsafe_queue.h:26