16 template <
typename Lock>
20 { lock.try_lock() } -> std::convertible_to<bool>;
23 template <
typename T,
typename Lock = std::mutex>
28 using size_type =
typename std::deque<T>::size_type;
33 std::scoped_lock lock(mutex_);
34 data_.push_back(std::forward<T>(value));
38 std::scoped_lock lock(mutex_);
39 data_.push_front(std::forward<T>(value));
42 [[nodiscard]]
bool empty()
const {
43 std::scoped_lock lock(mutex_);
48 std::scoped_lock lock(mutex_);
49 if (data_.empty())
return std::nullopt;
51 auto front = std::move(data_.front());
57 std::scoped_lock lock(mutex_);
58 if (data_.empty())
return std::nullopt;
60 auto back = std::move(data_.back());
65 [[nodiscard]] std::optional<T>
steal() {
66 std::scoped_lock lock(mutex_);
67 if (data_.empty())
return std::nullopt;
69 auto back = std::move(data_.back());
75 std::scoped_lock lock(mutex_);
76 auto iter = std::find(data_.begin(), data_.end(), item);
78 if (iter != data_.end()) {
79 std::ignore = data_.erase(iter);
82 data_.push_front(item);
86 std::scoped_lock lock(mutex_);
88 if (data_.empty())
return std::nullopt;
90 auto front = data_.front();
93 data_.push_back(front);
99 std::deque<T> data_{};
100 mutable Lock mutex_{};
Definition thread_safe_queue.h:25
std::optional< T > copy_front_and_rotate_to_back()
Definition thread_safe_queue.h:85
std::optional< T > steal()
Definition thread_safe_queue.h:65
void push_front(T &&value)
Definition thread_safe_queue.h:37
void push_back(T &&value)
Definition thread_safe_queue.h:32
thread_safe_queue()=default
T value_type
Definition thread_safe_queue.h:27
std::optional< T > pop_back()
Definition thread_safe_queue.h:56
typename std::deque< T >::size_type size_type
Definition thread_safe_queue.h:28
bool empty() const
Definition thread_safe_queue.h:42
void rotate_to_front(const T &item)
Definition thread_safe_queue.h:74
std::optional< T > pop_front()
Definition thread_safe_queue.h:47
Simple concept for the Lockable and Basic Lockable types as defined by the C++ standard.
Definition thread_safe_queue.h:17
Definition thread_pool.h:21