5#include "declarations.hpp"
6#include "../utility/small_vector.hpp"
71 friend class Executor;
113 void reset(
size_t new_max_value);
117 mutable std::mutex _mtx;
119 size_t _max_value{0};
120 size_t _cur_value{0};
122 SmallVector<Node*> _waiters;
124 bool _try_acquire_or_wait(Node*);
126 void _release(SmallVector<Node*>&);
134inline bool Semaphore::_try_acquire_or_wait(Node* me) {
135 std::lock_guard<std::mutex> lock(_mtx);
141 _waiters.push_back(me);
148 std::lock_guard<std::mutex> lock(_mtx);
150 if(_cur_value >= _max_value) {
151 TF_THROW(
"can't release the semaphore more than its maximum value: ", _max_value);
160 dst.reserve(dst.size() + _waiters.size());
161 dst.insert(dst.end(), _waiters.begin(), _waiters.end());
171 std::lock_guard<std::mutex> lock(_mtx);
176 std::lock_guard<std::mutex> lock(_mtx);
177 _cur_value = _max_value;
182 std::lock_guard<std::mutex> lock(_mtx);
183 _cur_value = (_max_value = new_max_value);
size_t max_value() const
queries the maximum allowable value of this semaphore
Definition semaphore.hpp:166
Semaphore()=default
constructs a default semaphore
size_t value() const
queries the current counter value
Definition semaphore.hpp:170
void reset()
resets the semaphores to a clean state
Definition semaphore.hpp:175
class to define a vector optimized for small array
Definition small_vector.hpp:931
taskflow namespace
Definition small_vector.hpp:20