YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
condition_variable_any.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <yaclib_std/chrono>
6#include <yaclib_std/mutex>
7
8namespace yaclib::detail {
9
10// TODO(myannyax) Maybe implement wait overloads with stop_token
11
12template <typename Impl>
13class ConditionVariableAny : private Impl {
14 public:
15 using Impl::Impl;
16
18 YACLIB_INJECT_FAULT(Impl::notify_one());
19 }
21 YACLIB_INJECT_FAULT(Impl::notify_all());
22 }
23
24 template <typename Lock>
25 void wait(Lock& lock) {
26 YACLIB_INJECT_FAULT(Impl::wait(lock));
27 }
28 template <typename Lock, typename Predicate>
29 void wait(Lock& lock, Predicate&& stop_waiting) {
30 YACLIB_INJECT_FAULT(Impl::wait(lock, std::forward<Predicate>(stop_waiting)));
31 }
32
33 template <typename Lock, typename Rep, typename Period>
34 std::cv_status wait_for(Lock& lock, const std::chrono::duration<Rep, Period>& rel_time) {
35 YACLIB_INJECT_FAULT(auto r = Impl::wait_for(lock, rel_time));
36 return r;
37 }
38 template <typename Lock, typename Rep, typename Period, typename Predicate>
39 bool wait_for(Lock& lock, const std::chrono::duration<Rep, Period>& rel_time, Predicate&& stop_waiting) {
40 YACLIB_INJECT_FAULT(auto r = Impl::wait_for(lock, rel_time, std::forward<Predicate>(stop_waiting)));
41 return r;
42 }
43
44 template <typename Lock, typename Clock, typename Duration>
45 std::cv_status wait_until(Lock& lock, const std::chrono::time_point<Clock, Duration>& timeout_time) {
46 YACLIB_INJECT_FAULT(auto r = Impl::wait_until(lock, timeout_time));
47 return r;
48 }
49 template <typename Lock, typename Clock, typename Duration, typename Predicate>
50 bool wait_until(Lock& lock, const std::chrono::time_point<Clock, Duration>& timeout_time, Predicate&& stop_waiting) {
51 YACLIB_INJECT_FAULT(auto r = Impl::wait_until(lock, timeout_time, std::forward<Predicate>(stop_waiting)));
52 return r;
53 }
54};
55
56} // namespace yaclib::detail
void wait(Lock &lock, Predicate &&stop_waiting)
bool wait_for(Lock &lock, const std::chrono::duration< Rep, Period > &rel_time, Predicate &&stop_waiting)
std::cv_status wait_for(Lock &lock, const std::chrono::duration< Rep, Period > &rel_time)
bool wait_until(Lock &lock, const std::chrono::time_point< Clock, Duration > &timeout_time, Predicate &&stop_waiting)
std::cv_status wait_until(Lock &lock, const std::chrono::time_point< Clock, Duration > &timeout_time)
#define YACLIB_INJECT_FAULT(statement)
Definition inject.hpp:20
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25