YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_timed_mutex.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <yaclib_std/chrono>
6
7namespace yaclib::detail::fiber {
8
10 using Base = SharedMutex;
11
12 public:
13 using Base::Base;
14
15 template <typename Rep, typename Period>
16 bool try_lock_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
17 return TimedWaitHelper(timeout_duration, true);
18 }
19
20 template <typename Clock, typename Duration>
21 bool try_lock_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
22 return TimedWaitHelper(timeout_time, true);
23 }
24
25 template <typename Rep, typename Period>
26 bool try_lock_shared_for(const std::chrono::duration<Rep, Period>& timeout_duration) {
27 return TimedWaitHelper(timeout_duration, false);
28 }
29
30 template <typename Clock, typename Duration>
31 bool try_lock_shared_until(const std::chrono::time_point<Clock, Duration>& timeout_time) {
32 return TimedWaitHelper(timeout_time, false);
33 }
34
35 private:
36 template <typename Timeout>
37 bool TimedWaitHelper(const Timeout& timeout, bool exclusive) {
38 bool r = true;
40 if (exclusive) {
42 } else {
44 }
45 }
46 YACLIB_DEBUG(r && _occupied && (exclusive || _exclusive_mode), "about to be locked twice and not in a good way");
47 if (r) {
49 }
50 return r;
51 }
52};
53
54} // namespace yaclib::detail::fiber
WaitStatus Wait(NoTimeoutTag)
Definition queue.cpp:5
bool try_lock_shared_for(const std::chrono::duration< Rep, Period > &timeout_duration)
bool try_lock_until(const std::chrono::time_point< Clock, Duration > &timeout_time)
bool try_lock_shared_until(const std::chrono::time_point< Clock, Duration > &timeout_time)
bool try_lock_for(const std::chrono::duration< Rep, Period > &timeout_duration)
#define YACLIB_DEBUG(cond, message)
Definition log.hpp:84
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25