25 #ifndef TASKOLIB_LOCKEDQUEUE_H_
26 #define TASKOLIB_LOCKEDQUEUE_H_
28 #include <condition_variable>
32 #include <gul17/SlidingBuffer.h>
65 template <
typename MessageT>
82 std::lock_guard<std::mutex> lock(
mutex_);
89 std::lock_guard<std::mutex> lock(
mutex_);
102 std::unique_lock<std::mutex> lock(
mutex_);
107 auto msg = std::move(
queue_.front());
122 std::unique_lock<std::mutex> lock(
mutex_);
137 template <
typename MsgT,
138 std::enable_if_t<std::is_convertible_v<MsgT, MessageType>,
bool> =
true>
141 std::unique_lock<std::mutex> lock(
mutex_);
146 queue_.push_back(std::forward<MsgT>(msg));
154 std::lock_guard<std::mutex> lock(
mutex_);
167 std::unique_lock<std::mutex> lock(
mutex_);
172 auto msg = std::move(
queue_.front());
188 template <
typename MsgT,
189 std::enable_if_t<std::is_convertible_v<MsgT, MessageType>,
bool> =
true>
192 std::unique_lock<std::mutex> lock(
mutex_);
197 queue_.push_back(std::forward<MsgT>(msg));
213 gul17::SlidingBuffer<MessageType>
queue_;
A thread-safe locking message queue.
Definition: LockedQueue.h:67
SizeType size() const
Return the number of messages in the queue.
Definition: LockedQueue.h:152
SizeType size_type
Definition: LockedQueue.h:72
SizeType capacity() const
Return the maximal number of entries in the queue.
Definition: LockedQueue.h:80
gul17::SlidingBuffer< MessageType > queue_
Definition: LockedQueue.h:213
std::uint32_t SizeType
Definition: LockedQueue.h:71
std::optional< MessageType > try_pop()
Remove a message from the front of the queue and return it.
Definition: LockedQueue.h:165
MessageT MessageType
Definition: LockedQueue.h:69
std::mutex mutex_
Mutex protecting all member variables.
Definition: LockedQueue.h:205
MessageT message_type
Definition: LockedQueue.h:70
LockedQueue(SizeType capacity)
Construct a queue that is able to hold a given maximum number of entries.
Definition: LockedQueue.h:75
bool empty() const
Determine whether the queue is empty.
Definition: LockedQueue.h:87
std::condition_variable cv_message_available_
Condition variable, triggered when at least one message has been added to the queue.
Definition: LockedQueue.h:208
MessageType pop()
Remove a message from the front of the queue and return it.
Definition: LockedQueue.h:100
void push(MsgT &&msg)
Insert a message at the end of the queue.
Definition: LockedQueue.h:139
MessageType back() const
Fetch the last message pushed to the queue and returns a copy of it.
Definition: LockedQueue.h:120
std::condition_variable cv_slot_available_
Condition variable, triggered when at least one slot in the queue has been freed.
Definition: LockedQueue.h:211
bool try_push(MsgT &&msg)
Try to insert a message at the end of the queue.
Definition: LockedQueue.h:190
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33