YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
shared_mutex.cpp
Go to the documentation of this file.
1#include <fault/util.hpp>
2
4
5namespace yaclib::detail::fiber {
6
8 if (_occupied) {
9 _exclusive_queue.Wait(NoTimeoutTag{});
10 }
11 LockHelper();
12}
13
15 if (_occupied) {
16 return false;
17 }
18 LockHelper();
19 return true;
20}
21
23 const bool unlock_shared = !_shared_queue.Empty() && (_exclusive_queue.Empty() || GetRandNumber(2) == 0);
24 _occupied = false;
25 if (unlock_shared) {
27 } else {
29 }
30}
31
38
41 return false;
42 }
44 return true;
45}
46
54
56 _occupied = true;
57 _exclusive_mode = true;
58}
59
65
69
70} // namespace yaclib::detail::fiber
bool Empty() const noexcept
Definition queue.cpp:39
WaitStatus Wait(NoTimeoutTag)
Definition queue.cpp:5
std::uint64_t GetRandNumber(std::uint64_t max)
Definition util.cpp:22
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25