All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Public Member Functions | List of all members
ucxx::utils::CallbackNotifier Class Reference

#include <callback_notifier.h>

Public Member Functions

 CallbackNotifier ()
 Construct a thread-safe notification object. More...
 
 CallbackNotifier (const CallbackNotifier &)=delete
 
CallbackNotifieroperator= (CallbackNotifier const &)=delete
 
 CallbackNotifier (CallbackNotifier &&o)=delete
 
CallbackNotifieroperator= (CallbackNotifier &&o)=delete
 
void set ()
 Notify waiting threads that we are done and they can proceed. More...
 
bool wait (uint64_t period=0, std::function< void(void)> signalWorkerFunction=nullptr, uint64_t signalRerun=100000000)
 Wait until set() has been called or period has elapsed. More...
 

Detailed Description

A thread-safe notification object.

A thread-safe notification object which can signal release of some shared state while a single thread blocks until the shared state is released.

Constructor & Destructor Documentation

◆ CallbackNotifier()

ucxx::utils::CallbackNotifier::CallbackNotifier ( )
inline

Construct a thread-safe notification object.

Construct a thread-safe notification object which can signal release of some shared state with set() while a single thread blocks on wait() until the shared state is released.

If libc is glibc and the version is older than 2.25, the implementation uses a spinlock otherwise it uses a condition variable.

When C++-20 is the minimum supported version, it should use atomic.wait + notify_one.

Member Function Documentation

◆ set()

void ucxx::utils::CallbackNotifier::set ( )

Notify waiting threads that we are done and they can proceed.

Set the flag to true and notify a single thread blocked by a call to wait(). See also std::condition_variable::notify_one.

◆ wait()

bool ucxx::utils::CallbackNotifier::wait ( uint64_t  period = 0,
std::function< void(void)>  signalWorkerFunction = nullptr,
uint64_t  signalRerun = 100000000 
)

Wait until set() has been called or period has elapsed.

Wait until set() has been called, or period (in nanoseconds) has elapsed (only applicable if using glibc 2.25 and higher). Optionally may receive a function to periodically signal the worker to wake the progress event, thus preventing potential deadlocks when the worker hasn't woken up for too long due to lack of UCX communication events.

See also std::condition_variable::wait.

Parameters
[in]periodmaximum period in nanoseconds to wait for or 0 to wait forever.
[in]signalWorkerFunctionfunction to signal worker to wake the progress event when in blocking mode.
[in]signalReruninterval to rerun the signal worker function.
Returns
true if waiting finished or false if a timeout occurred.

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