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

Thread-safe queue with blocking and shutdown-aware consumers. More...

#include <src/thread_safe.h>

Public Types

using status_t = util::optional_t<T>
 Value type stored in the queue.
 

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<class Rep , class Period >
status_t pop (std::chrono::duration< Rep, Period > delay)
 Remove and return the next queued item, waiting when requested.
 
 queue_t (std::uint32_t max_elements=32)
 Construct a bounded blocking queue.
 
template<class... Args>
void raise (Args &&...args)
 Notify waiters that a new event value is available.
 
bool running () const
 Return whether the queue is still running.
 
void stop ()
 Shut down the queue and wake blocked consumers.
 
std::vector< T > & unsafe ()
 Return the wrapped pointer without synchronization checks.
 

Detailed Description

template<class T>
class safe::queue_t< T >

Thread-safe queue with blocking and shutdown-aware consumers.

Constructor & Destructor Documentation

◆ queue_t()

template<class T >
safe::queue_t< T >::queue_t ( std::uint32_t max_elements = 32)
inline

Construct a bounded blocking queue.

Parameters
max_elementsMaximum number of queued elements before producers block.

Member Function Documentation

◆ peek()

template<class T >
bool safe::queue_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::queue_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<class Rep , class Period >
status_t safe::queue_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::queue_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::queue_t< T >::running ( ) const
inlinenodiscard

Return whether the queue is still running.

Returns
True while the queue accepts producers and consumers.

◆ unsafe()

template<class T >
std::vector< T > & safe::queue_t< T >::unsafe ( )
inline

Return the wrapped pointer without synchronization checks.

Returns
Mutable queue storage for callers that already hold external synchronization.

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