YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
timed_mutex.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <yaclib_std/chrono>
7
8namespace yaclib::detail {
9
10template <typename Impl>
11class TimedMutex : public Mutex<Impl> {
12 using Base = Mutex<Impl>;
13
14 public:
15 using Base::Base;
16
17 template <typename Rep, typename Period>
18 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
19 YACLIB_INJECT_FAULT(auto r = Impl::try_lock_for(timeout_duration));
20 return r;
21 }
22
23 template <typename Clock, typename Duration>
24 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
25 YACLIB_INJECT_FAULT(auto r = Impl::try_lock_until(timeout_time));
26 return r;
27 }
28};
29
30} // namespace yaclib::detail
bool try_lock_for(const std::chrono::duration< Rep, Period > &timeout_duration)
bool try_lock_until(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