25 #include <boost/fiber/condition_variable.hpp>
26 #include <boost/fiber/mutex.hpp>
56 template <
typename T,
typename MutexType,
typename ConditionVariableType>
66 std::scoped_lock lock(mutex_);
67 return queue_.empty();
74 std::scoped_lock lock(mutex_);
82 std::scoped_lock lock(mutex_);
83 return closed_ && queue_.empty();
91 std::scoped_lock lock(mutex_);
94 condition_variable_.notify_all();
102 throw std::logic_error(
"Tried to enqueue in closed BasicSynchronizedQueue");
105 std::scoped_lock lock(mutex_);
108 condition_variable_.notify_one();
113 throw std::logic_error(
"Tried to enqueue in closed BasicSynchronizedQueue");
116 std::scoped_lock lock(mutex_);
117 queue_.push(std::move(item));
119 condition_variable_.notify_one();
126 std::unique_lock lock(mutex_);
127 if (queue_.empty() && closed_) {
130 if (queue_.empty() && !closed_) {
131 condition_variable_.wait(lock, [
this] {
return !this->queue_.empty() || this->closed_; });
133 if (queue_.empty()) {
137 auto item = std::move(queue_.front());
140 return std::optional<T>(std::move(item));
147 std::queue<T> output;
148 std::unique_lock lock(mutex_);
149 if (queue_.empty() && closed_) {
152 if (queue_.empty() && !closed_) {
153 condition_variable_.wait(lock, [
this] {
return !this->queue_.empty() || this->closed_; });
155 if (queue_.empty()) {
160 return std::optional<std::queue<T>>(std::move(output));
164 bool closed_ =
false;
165 std::queue<T> queue_;
166 mutable MutexType mutex_;
167 ConditionVariableType condition_variable_;
170 template <
typename T>
173 template <
typename T>