YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
mutex_event.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/util/ref.hpp>
4
5#include <chrono>
6#include <yaclib_std/condition_variable>
7#include <yaclib_std/mutex>
8
9namespace yaclib::detail {
10
12 public:
13 using Token = std::unique_lock<yaclib_std::mutex>;
14
16
17 void Wait(Token& token) noexcept;
18
20 bool Wait(Token& token, const std::chrono::duration<Rep, Period>& timeout_duration) noexcept {
21 return _cv.wait_for(token, timeout_duration, [&] {
22 return _is_ready;
23 });
24 }
25
26 template <typename Clock, typename Duration>
27 bool Wait(Token& token, const std::chrono::time_point<Clock, Duration>& timeout_time) noexcept {
28 return _cv.wait_until(token, timeout_time, [&] {
29 return _is_ready;
30 });
31 }
32
33 void Set() noexcept;
34
35 void Reset() noexcept;
36
37 private:
38 bool _is_ready = false;
39 yaclib_std::mutex _m;
40 yaclib_std::condition_variable _cv;
41};
42
43} // namespace yaclib::detail
std::unique_lock< yaclib_std::mutex > Token
void Wait(Token &token) noexcept
bool Wait(Token &token, const std::chrono::time_point< Clock, Duration > &timeout_time) noexcept
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25