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
6namespace yaclib::detail::fiber {
7
8class TimedMutex : public Mutex {
9 using Base = Mutex;
10
11 public:
12 using Base::Base;
13
14 template <typename Rep, typename Period>
15 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
16 return TimedWaitHelper(timeout_duration);
17 }
18
19 template <typename Clock, typename Duration>
20 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
21 return TimedWaitHelper(timeout_time);
22 }
23
24 private:
25 template <typename Timeout>
26 bool TimedWaitHelper(const Timeout& timeout) {
27 bool r = true;
28 if (_occupied) {
30 }
31 YACLIB_DEBUG(r && _occupied, "about to be locked twice");
32 if (r) {
33 _occupied = true;
34 }
35 return r;
36 }
37};
38
39} // namespace yaclib::detail::fiber
WaitStatus Wait(NoTimeoutTag)
Definition queue.cpp:5
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_DEBUG(cond, message)
Definition log.hpp:84
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25