28concept waiter =
requires (
volatile void * p, uint32_t t) {
41 [[assume(W::supported)]];
87 else k.template operator()<
spin>();
93#if defined(EIN_TESTING) || defined(EIN_TESTING_WAIT)
100 static inline bool supported =
true;
101 static inline std::atomic<bool> monitor_called =
false;
102 static inline std::atomic<bool> mwait_called =
false;
104 static void monitor(
volatile void*)
noexcept {
105 monitor_called.store(
true);
108 static void mwait(uint32_t timer = 0) noexcept {
109 mwait_called.store(
true);
110 std::this_thread::sleep_for(std::chrono::milliseconds(timer));
115TEST_CASE(
"wait",
"[wait]") {
117 SECTION(
"wait_until with mock_waiter") {
120 volatile int data = 0;
121 auto predicate = [](
volatile int* p) {
return *p == 42; };
123 std::thread updater([&data]() {
124 std::this_thread::sleep_for(std::chrono::milliseconds(100));
128 wait_until<mock_waiter>(&data, predicate);
130 CHECK(mock_waiter::monitor_called.load());
131 CHECK(mock_waiter::mwait_called.load());
137 SECTION(
"wait_until with platform waiter") {
140 volatile int data = 0;
141 auto predicate = [](
volatile int* p) {
return *p == 42; };
143 std::thread updater([&data]() {
144 std::this_thread::sleep_for(std::chrono::milliseconds(100));
149 wait_until<w>(&data, predicate);
some way to wait for a value to change
#define ein_artificial
[[artificial]].
#define ein_flatten
portable [[flatten]]
#define ein_inline
inline [[always_inline]]
static void mwait(uint32_t=0) noexcept ein_blocking
static void monitor(volatile void *p) noexcept
static uint8_t mwait(uint32_t timer=0) noexcept ein_blocking
static void monitor(volatile void *p) noexcept
static void monitor(volatile void *) noexcept
static const bool supported
static const bool supported
static constinit bool supported
static void mwait(uint32_t timer=0) noexcept ein_blocking
auto with_waiter(auto k) noexcept
finds an appropriate waiter for the current CPU
ein_flatten void wait_until(volatile auto *p, auto f) noexcept ein_blocking
Wait until a predicate holds about a given memory location.
waiter using MONITORX/MWAITX for AMD
waiter using UMONITOR/UMWAIT for Intel