NAP
Public Types | Public Member Functions | List of all members
AutoResetEvent Class Reference

#include </opt/build/repo/nap/utility/src/utility/autoresetevent.h>

Public Types

enum  EWaitResult { Completed, Canceled }
 
using LockedWaitCallback = std::function< void(EWaitResult)>
 
using LockedSetCallback = std::function< void()>
 

Public Member Functions

void reset ()
 
EWaitResult wait (const LockedWaitCallback &callback=LockedWaitCallback())
 
void set (const LockedSetCallback &callback=LockedSetCallback())
 
void cancelWait ()
 

Description

Helper class that implements an AutoResetEvent on top of condition_variable. You can use this to wait for an event to happen; once the wait completes, the event is reset and you can wait on the event again. If the event is set before the wait is entered, the wait completes immediately and resets the event.

Member Typedef Documentation

◆ LockedSetCallback

using LockedSetCallback = std::function<void()>

◆ LockedWaitCallback

using LockedWaitCallback = std::function<void(EWaitResult)>

Member Enumeration Documentation

◆ EWaitResult

enum EWaitResult
strong

The result of the wait on the event

Enumerator
Completed 

The wait completed successfully (i.e. the event was signaled normally)

Canceled 

The wait was canceled.

Member Function Documentation

◆ cancelWait()

void cancelWait ( )

If any threads are waiting on the event, cancel their waits

◆ reset()

void reset ( )

Resets the event to a non-signaled, non-canceled state

◆ set()

void set ( const LockedSetCallback callback = LockedSetCallback())

Signal the event, unblocking any threads waiting on it

Parameters
callbackAn optional callback that is called when the set completes. This callback has the special property that it is executed during the same lock as the wait() function. This makes the code executing in the callback effectively an 'atomic' operation with the set.

◆ wait()

EWaitResult wait ( const LockedWaitCallback callback = LockedWaitCallback())

Wait for the event to be signaled. This is an infinite wait, which can be canceled by calling cancelWait()

Parameters
callbackAn optional callback that is called when the wait completes. This callback has the special property that it is executed during the same lock as the set() function. This makes the code executing in the callback effectively an 'atomic' operation with the wait.
Returns
The result of the wait (completed or canceled)