Flow 3.0.0
Flow project: Full implementation reference.
Public Member Functions | Private Attributes | 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>

Inheritance diagram for flow::util::Poll_flag:
[legend]
Collaboration diagram for flow::util::Poll_flag:
[legend]

Public Member Functions

 Poll_flag ()
 Creates flag in disarmed state: poll_armed() shall return false until the first arm_next_poll(). More...
 
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...
 

Private Attributes

std::atomic< bool > m_armed
 The flag; true = armed. 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.

Definition at line 817 of file thread_lcl.hpp.

Constructor & Destructor Documentation

◆ Poll_flag()

flow::util::Poll_flag::Poll_flag ( )
inline

Creates flag in disarmed state: poll_armed() shall return false until the first arm_next_poll().

Definition at line 1325 of file thread_lcl.hpp.

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.

Definition at line 1331 of file thread_lcl.hpp.

References m_armed.

◆ 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.

Definition at line 1358 of file thread_lcl.hpp.

References m_armed.

Member Data Documentation

◆ m_armed

std::atomic<bool> flow::util::Poll_flag::m_armed
private

The flag; true = armed.

Definition at line 850 of file thread_lcl.hpp.

Referenced by arm_next_poll(), and poll_armed().


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