Sunshine master
Self-hosted game stream host for Moonlight.
safe::event_t< T > Class Template Reference

Thread-safe event value that blocks readers until a value is raised. More...

#include <src/thread_safe.h>

Public Types

using status_t = util::optional_t<T>
 Status value stored in the event.
 

Public Member Functions

bool peek ()
 Inspect the next queued value without popping it.
 
status_t pop ()
 Remove and return the next queued item, waiting when requested.
 
template<typename Rep , typename Period >
status_t pop (std::chrono::duration< Rep, Period > delay)
 Remove and return the next queued item, waiting when requested.
 
template<class... Args>
void raise (Args &&...args)
 Notify waiters that a new event value is available.
 
void reset ()
 Reset the object to its initial empty state.
 
bool running () const
 Return whether the queue is still running.
 
void stop ()
 Raise the alarm and wake all waiting threads.
 
status_t try_pop ()
 Try to remove and return the next queued item without any further wait.
 
status_t view ()
 Read the current value without removing it from the queue.
 
template<class Rep , class Period >
status_t view (std::chrono::duration< Rep, Period > delay)
 Read the current value without removing it from the queue.
 

Detailed Description

template<class T>
class safe::event_t< T >

Thread-safe event value that blocks readers until a value is raised.

Member Function Documentation

◆ peek()

template<class T >
bool safe::event_t< T >::peek ( )
inline

Inspect the next queued value without popping it.

Returns
True when a value is available to inspect.

◆ pop() [1/2]

template<class T >
status_t safe::event_t< T >::pop ( )
inline

Remove and return the next queued item, waiting when requested.

Returns
Removed queue item, or empty result when the queue is stopped or empty.

◆ pop() [2/2]

template<class T >
template<typename Rep , typename Period >
status_t safe::event_t< T >::pop ( std::chrono::duration< Rep, Period > delay)
inline

Remove and return the next queued item, waiting when requested.

Parameters
delayMaximum wait duration before timing out.
Returns
Removed queue item, or empty result when the queue is stopped or empty.

◆ raise()

template<class T >
template<class... Args>
void safe::event_t< T >::raise ( Args &&... args)
inline

Notify waiters that a new event value is available.

Parameters
argsArguments forwarded to the callable or parser.

◆ running()

template<class T >
bool safe::event_t< T >::running ( ) const
inlinenodiscard

Return whether the queue is still running.

Returns
True while the queue accepts producers and consumers.

◆ try_pop()

template<class T >
status_t safe::event_t< T >::try_pop ( )
inline

Try to remove and return the next queued item without any further wait.

Returns
Removed queue item, or empty result when the queue is stopped or empty.

◆ view() [1/2]

template<class T >
status_t safe::event_t< T >::view ( )
inline

Read the current value without removing it from the queue.

Returns
Optional copy of the front item, or empty status when the queue is closed.

◆ view() [2/2]

template<class T >
template<class Rep , class Period >
status_t safe::event_t< T >::view ( std::chrono::duration< Rep, Period > delay)
inline

Read the current value without removing it from the queue.

Parameters
delayMaximum wait duration before timing out.
Returns
Optional copy of the front item, or empty status after timeout/closure.

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