一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
Waiting

Files

file  wait.hpp
 waiting strategies
 

Concepts

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

Classes

struct  ein::mwaitx
 waiter using MONITORX/MWAITX for AMD More...
 
struct  ein::umwait
 waiter using UMONITOR/UMWAIT for Intel More...
 
struct  ein::spin
 spin waiter using PAUSE More...
 

Functions

template<waiter W>
ein_flatten void ein::wait_until (volatile auto *p, auto f) noexcept ein_blocking
 Wait until a predicate holds about a given memory location.
 
auto ein::with_waiter (auto k) noexcept
 finds an appropriate waiter for the current CPU
 

Detailed Description


Class Documentation

◆ ein::mwaitx

struct ein::mwaitx

waiter using MONITORX/MWAITX for AMD

Definition at line 50 of file wait.hpp.

Public Types

using timer_t = uint64_t
 

Static Public Member Functions

static void monitor (volatile void *p) noexcept
 
static void mwait (uint32_t timer=0) noexcept ein_blocking
 

Static Public Attributes

static const bool supported
 

Member Typedef Documentation

◆ timer_t

using ein::mwaitx::timer_t = uint64_t

Definition at line 51 of file wait.hpp.

Member Function Documentation

◆ monitor()

static void ein::mwaitx::monitor ( volatile void * p)
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 52 of file wait.hpp.

52{ _mm_monitorx(const_cast<void*>(p),0,0); }

◆ mwait()

static void ein::mwaitx::mwait ( uint32_t timer = 0)
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 53 of file wait.hpp.

53{ _mm_mwaitx(0,0,timer); }

Member Data Documentation

◆ supported

const bool ein::mwaitx::supported
static

Definition at line 55 of file wait.hpp.

Referenced by ein::with_waiter().

◆ ein::umwait

struct ein::umwait

waiter using UMONITOR/UMWAIT for Intel

Definition at line 60 of file wait.hpp.

Public Types

using timer_t = uint64_t
 

Static Public Member Functions

static void monitor (volatile void *p) noexcept
 
static uint8_t mwait (uint32_t timer=0) noexcept ein_blocking
 

Static Public Attributes

static const bool supported
 

Member Typedef Documentation

◆ timer_t

using ein::umwait::timer_t = uint64_t

Definition at line 61 of file wait.hpp.

Member Function Documentation

◆ monitor()

static void ein::umwait::monitor ( volatile void * p)
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 62 of file wait.hpp.

62{ return _umonitor(const_cast<void*>(p)); }

◆ mwait()

static uint8_t ein::umwait::mwait ( uint32_t timer = 0)
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 63 of file wait.hpp.

63{ return _umwait(1,timer); }

Member Data Documentation

◆ supported

const bool ein::umwait::supported
static

Definition at line 65 of file wait.hpp.

Referenced by ein::with_waiter().

◆ ein::spin

struct ein::spin

spin waiter using PAUSE

Definition at line 69 of file wait.hpp.

Public Types

using timer_t = uint64_t
 

Static Public Member Functions

static void monitor (volatile void *) noexcept
 
static void mwait (uint32_t=0) noexcept ein_blocking
 

Static Public Attributes

static constinit bool supported = true
 

Member Typedef Documentation

◆ timer_t

using ein::spin::timer_t = uint64_t

Definition at line 70 of file wait.hpp.

Member Function Documentation

◆ monitor()

static void ein::spin::monitor ( volatile void * )
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 71 of file wait.hpp.

71{}

◆ mwait()

static void ein::spin::mwait ( uint32_t = 0)
inlinestaticnoexcept[[always_inline]][[artificial]]

Definition at line 72 of file wait.hpp.

72{ _mm_pause(); }

Member Data Documentation

◆ supported

bool ein::spin::supported = true
inlinestaticconstinit

Definition at line 74 of file wait.hpp.

Function Documentation

◆ wait_until()

template<waiter W>
ein_flatten void ein::wait_until ( volatile auto * p,
auto f )
noexcept

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
Postcondition
f(p)

Definition at line 40 of file wait.hpp.

40 {
41 [[assume(W::supported)]];
42 while (!f(p)) {
43 W::monitor(p);
44 if (!f(p))
45 W::mwait(0);
46 }
47}

◆ with_waiter()

auto ein::with_waiter ( auto k)
noexcept

finds an appropriate waiter for the current CPU

Chooses between variations of user-mode MONITOR / MWAIT. Usage:

with_waiter([]<waiter w> noexcept { ...; wait_until<w>(p,f); ... });
some way to wait for a value to change
Definition wait.hpp:28
auto with_waiter(auto k) noexcept
finds an appropriate waiter for the current CPU
Definition wait.hpp:84
ein_flatten void wait_until(volatile auto *p, auto f) noexcept ein_blocking
Wait until a predicate holds about a given memory location.
Definition wait.hpp:40

invokes k with a waiter as a template parameter.

Definition at line 84 of file wait.hpp.

84 {
85 if (mwaitx::supported) return k.template operator()<mwaitx>();
86 else if (umwait::supported) return k.template operator()<umwait>();
87 else k.template operator()<spin>();
88}

References ein::mwaitx::supported, and ein::umwait::supported.