22 semaphore(
unsigned long counter): _counter (counter) {}
34 std::lock_guard _(_mx);
39 _waiting.push(std::move(
promise));
61 std::lock_guard _(_mx);
62 if (_waiting.empty()) {
65 r = _waiting.front()();
80 std::lock_guard _(_mx);
81 if (_counter)
return static_cast<long>(_counter);
82 return -
static_cast<long>(_waiting.size());
92 std::lock_guard _(_mx);
93 if (!_counter)
return false;
100 unsigned long _counter = 0;
102 std::queue<coro::promise<void> > _waiting;
contain notification to be delivered to the asociated future
Carries reference to future<T>, callable, sets value of an associated future<T>
semaphore()=default
construct semaphore with counter set to zero
bool try_acquire()
Try acquire the semaphore.
coro::future< void > acquire()
acquire the semaphore
coro::promise< void >::notify release()
Release the semaphore.
long get()
Retrieve counter.
Implements semaphore for coroutines.