25 #ifndef TASKOLIB_LOCKEDQUEUE_H_
26 #define TASKOLIB_LOCKEDQUEUE_H_
28 #include <condition_variable>
30 #include <gul14/optional.h>
31 #include <gul14/SlidingBuffer.h>
64 template <
typename MessageT>
81 std::lock_guard<std::mutex> lock(
mutex_);
88 std::lock_guard<std::mutex> lock(
mutex_);
101 std::unique_lock<std::mutex> lock(
mutex_);
106 auto msg = std::move(
queue_.front());
121 std::unique_lock<std::mutex> lock(
mutex_);
136 template <
typename MsgT,
137 std::enable_if_t<std::is_convertible_v<MsgT, MessageType>,
bool> =
true>
140 std::unique_lock<std::mutex> lock(
mutex_);
145 queue_.push_back(std::forward<MsgT>(msg));
153 std::lock_guard<std::mutex> lock(
mutex_);
166 std::unique_lock<std::mutex> lock(
mutex_);
169 return gul14::nullopt;
171 auto msg = std::move(
queue_.front());
187 template <
typename MsgT,
188 std::enable_if_t<std::is_convertible_v<MsgT, MessageType>,
bool> =
true>
191 std::unique_lock<std::mutex> lock(
mutex_);
196 queue_.push_back(std::forward<MsgT>(msg));
212 gul14::SlidingBuffer<MessageType>
queue_;
A thread-safe locking message queue.
Definition: LockedQueue.h:66
SizeType size() const
Return the number of messages in the queue.
Definition: LockedQueue.h:151
SizeType size_type
Definition: LockedQueue.h:71
SizeType capacity() const
Return the maximal number of entries in the queue.
Definition: LockedQueue.h:79
std::uint32_t SizeType
Definition: LockedQueue.h:70
MessageT MessageType
Definition: LockedQueue.h:68
std::mutex mutex_
Mutex protecting all member variables.
Definition: LockedQueue.h:204
MessageT message_type
Definition: LockedQueue.h:69
LockedQueue(SizeType capacity)
Construct a queue that is able to hold a given maximum number of entries.
Definition: LockedQueue.h:74
bool empty() const
Determine whether the queue is empty.
Definition: LockedQueue.h:86
std::condition_variable cv_message_available_
Condition variable, triggered when at least one message has been added to the queue.
Definition: LockedQueue.h:207
gul14::optional< MessageType > try_pop()
Remove a message from the front of the queue and return it.
Definition: LockedQueue.h:164
MessageType pop()
Remove a message from the front of the queue and return it.
Definition: LockedQueue.h:99
gul14::SlidingBuffer< MessageType > queue_
Definition: LockedQueue.h:212
void push(MsgT &&msg)
Insert a message at the end of the queue.
Definition: LockedQueue.h:138
MessageType back() const
Fetch the last message pushed to the queue and returns a copy of it.
Definition: LockedQueue.h:119
std::condition_variable cv_slot_available_
Condition variable, triggered when at least one slot in the queue has been freed.
Definition: LockedQueue.h:210
bool try_push(MsgT &&msg)
Try to insert a message at the end of the queue.
Definition: LockedQueue.h:189
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33