YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
atomic_wait.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/config.hpp>
6
7namespace yaclib::detail::fiber {
8
9template <typename T>
11 public:
13
17 T operator=(T desired) volatile noexcept {
18 return _value = desired;
19 }
20
21 T operator=(T desired) noexcept {
22 return _value = desired;
23 }
24
26 return true;
27 }
28
30 return true;
31 }
32
33 static constexpr bool is_always_lock_free = true;
34
35#if YACLIB_FUTEX != 0
36 void wait(T old, std::memory_order) const noexcept {
37 while (_value == old) {
38 const_cast<FiberQueue*>(&_queue)->Wait(NoTimeoutTag{});
39 }
40 }
41 void wait(T old, std::memory_order) const volatile noexcept {
42 while (_value == old) {
43 const_cast<FiberQueue*>(&_queue)->Wait(NoTimeoutTag{});
44 }
45 }
46
47 void notify_one() noexcept {
48 _queue.NotifyOne();
49 }
50 void notify_one() volatile noexcept {
51 const_cast<FiberQueue*>(&_queue)->NotifyOne();
52 }
53
54 void notify_all() noexcept {
55 _queue.NotifyAll();
56 }
57 void notify_all() volatile noexcept {
58 const_cast<FiberQueue*>(&_queue)->NotifyAll();
59 }
60#endif
61
62 protected:
64#if YACLIB_FUTEX != 0
65 FiberQueue _queue;
66#endif
67};
68
69} // namespace yaclib::detail::fiber
bool is_lock_free() const noexcept
T operator=(T desired) noexcept
bool is_lock_free() const volatile noexcept
T operator=(T desired) volatile noexcept
static constexpr bool is_always_lock_free
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
YACLIB_INLINE void Wait(FutureBase< V, E > &... fs) noexcept
Wait until Ready becomes true.
Definition wait.hpp:18