Flow 3.0.0
Flow project: Public API.
Public Member Functions | List of all members
flow::util::Poll_flag Class Reference

A single boolean flag, armed via arm_next_poll() (typically from another thread) and both checked and disarmed – cheaply enough for the hottest of paths – via poll_armed(). More...

#include <thread_lcl.hpp>

Inherits boost::noncopyable.

Public Member Functions

 Poll_flag ()
 Creates flag in disarmed state: poll_armed() shall return false until the first arm_next_poll().
 
void arm_next_poll ()
 From any thread: causes the next poll_armed() call to return true (once). More...
 
bool poll_armed ()
 If armed: disarms and returns true; else returns false. More...
 

Detailed Description

A single boolean flag, armed via arm_next_poll() (typically from another thread) and both checked and disarmed – cheaply enough for the hottest of paths – via poll_armed().

It is the signaling building block of the Polled_shared_state pattern (see Polled_shared_state doc header), wherein one embeds a Poll_flag in each per-thread state of a Thread_local_state_registry; but it is usable stand-alone, wherever a thread must cheaply, opportunistically notice a rare request from another thread.

Member Function Documentation

◆ arm_next_poll()

void flow::util::Poll_flag::arm_next_poll ( )
inline

From any thread: causes the next poll_armed() call to return true (once).

If already armed, it stays armed (this is not a counter).

If arming signals a change to some shared data (e.g., Polled_shared_state::while_locked()-guarded state), finish writing that data – and unlock – before calling this; the memory-ordering internals then guarantee the poll_armed() caller sees the writes.

◆ poll_armed()

bool flow::util::Poll_flag::poll_armed ( )
inline

If armed: disarms and returns true; else returns false.

Cheap enough (one atomic op with near-minimal ordering constraints; no locking) for the hottest of paths, particularly when it returns false.

Returns
See above.

The documentation for this class was generated from the following file: