Condy v1.6.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
condy::Futex< T > Class Template Reference

User-space "futex" implementation for efficient synchronization between coroutines. More...

#include <futex.hpp>

Public Member Functions

 Futex (std::atomic< T > &futex)
 Construct a new Futex object.
WaitSender wait (T old) noexcept
 Wait if the futex value equals to the specified old value. The awaiting coroutine will be suspended until a notify is received. If the value of the futex is not equal to the old value, the awaiting coroutine will not be suspended.
void notify_one () noexcept
 Notify one awaiting coroutine, if any.
void notify_all () noexcept
 Notify all awaiting coroutines.

Detailed Description

template<typename T>
class condy::Futex< T >

User-space "futex" implementation for efficient synchronization between coroutines.

This class provides a user-space futex implementation that allows coroutines to wait on a futex value and be efficiently notified when the value changes. This class is different from condy::async_futex_wait(), the latter one can be used together with thread-based synchronous wait.

Template Parameters
TType of the futex value.

Definition at line 28 of file futex.hpp.

Constructor & Destructor Documentation

◆ Futex()

template<typename T>
condy::Futex< T >::Futex ( std::atomic< T > & futex)
inline

Construct a new Futex object.

Parameters
futexReference to the atomic variable used as the futex.

Definition at line 34 of file futex.hpp.

Member Function Documentation

◆ notify_all()

template<typename T>
void condy::Futex< T >::notify_all ( )
inlinenoexcept

Notify all awaiting coroutines.

Note
This function is thread-safe and can be called from any thread.

Definition at line 77 of file futex.hpp.

◆ notify_one()

template<typename T>
void condy::Futex< T >::notify_one ( )
inlinenoexcept

Notify one awaiting coroutine, if any.

Note
This function is thread-safe and can be called from any thread.

Definition at line 61 of file futex.hpp.

◆ wait()

template<typename T>
WaitSender condy::Futex< T >::wait ( T old)
inlinenoexcept

Wait if the futex value equals to the specified old value. The awaiting coroutine will be suspended until a notify is received. If the value of the futex is not equal to the old value, the awaiting coroutine will not be suspended.

Parameters
oldThe old value to compare with the futex value.
Returns
int32_t 0 if the wait operation is successful; -ECANCELED if the wait operation is canceled while waiting; -EIDRM if the futex is destroyed while waiting (usually indicates a lifetime management bug).

Definition at line 55 of file futex.hpp.


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