native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
Waiting helpers
Collaboration diagram for Waiting helpers:

Concepts

concept  native::waiter
 some way to wait for a value to change

Classes

struct  native::mwaitx
 waiter using the MONITORX/MWAITX instruction feature More...
struct  native::umwait
 waiter using the WAITPKG instruction feature More...
struct  native::spin
 A universally supported x86 spin waiter using PAUSE; monitor is a no-op. More...

Functions

template<waiter W>
void native::wait_until (volatile auto *p, auto f) noexcept(noexcept(!f(p)) &&noexcept(W::monitor(p)) &&noexcept(W::mwait(0))) native_blocking
 Wait until a predicate holds about a given memory location.
template<isa< x86 > Arch = NATIVE_BASELINE, unsigned Control = 1>
requires (Arch.has(x86_feature::waitpkg) && Control < 2)
std::uint8_t native::tpause (std::uint64_t deadline) noexcept native_blocking
auto native::with_waiter (auto k) noexcept(noexcept(k.template operator()<mwaitx >()) &&noexcept(k.template operator()<umwait >()) &&noexcept(k.template operator()<spin >()))
 finds an appropriate waiter for the current CPU Prefer MWAITX, then WAITPKG, otherwise PAUSE. Invoke k once with that type. Runtime detection occurs here, not in a SIMD arithmetic operation. Usage:

Detailed Description

Function Documentation

◆ tpause()

template<isa< x86 > Arch = NATIVE_BASELINE, unsigned Control = 1>
requires (Arch.has(x86_feature::waitpkg) && Control < 2)
std::uint8_t native::tpause ( std::uint64_t deadline)
inlineexportnoexcept

Wait until an absolute 64-bit TSC deadline without arming a monitor. Control 0 permits C0.2; Control 1 requests C0.1. The OS may limit the wait. Returns the intrinsic carry status; no memory ordering is promised. Call only after admitting WAITPKG on the executing CPU.

Definition at line 91 of file native.x86.wait.ccm.

Here is the caller graph for this function:

◆ wait_until()

template<waiter W>
void native::wait_until ( volatile auto * p,
auto f )
exportnoexcept

Wait until a predicate holds about a given memory location.

Parameters
ppointer to data. activity on its cache line will wake us up
fpredicate to check about the pointer
Precondition
W::supported is true. The predicate provides any required atomic synchronization; volatile access alone is not inter-thread synchronization. Wakeups may be spurious, so the predicate is checked again after monitoring.
Postcondition
f(p)
void capabilities() {
auto maximum_leaf = native::cpuid(0, 0).eax;
check(maximum_leaf >= 0);
// A real feature test must also admit the required OS vector state.
// Waiting is independent of SIMD architecture selection.
int ready = 1;
native::wait_until<native::spin>(&ready, [](volatile int * p) { return *p != 0; });
}

Definition at line 47 of file native.x86.wait.ccm.

Here is the caller graph for this function:

◆ with_waiter()

auto native::with_waiter ( auto k)
exportnoexcept

finds an appropriate waiter for the current CPU Prefer MWAITX, then WAITPKG, otherwise PAUSE. Invoke k once with that type. Runtime detection occurs here, not in a SIMD arithmetic operation. Usage:

some way to wait for a value to change
void wait_until(volatile auto *p, auto f) noexcept(noexcept(!f(p)) &&noexcept(W::monitor(p)) &&noexcept(W::mwait(0))) native_blocking
Wait until a predicate holds about a given memory location.
auto with_waiter(auto k) noexcept(noexcept(k.template operator()<mwaitx >()) &&noexcept(k.template operator()<umwait >()) &&noexcept(k.template operator()<spin >()))
finds an appropriate waiter for the current CPU Prefer MWAITX, then WAITPKG, otherwise PAUSE....

invokes k with a waiter as a template parameter.

Definition at line 115 of file native.x86.wait.ccm.

Here is the caller graph for this function: