Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
safe::queue_t< T > Class Template Reference

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

#include <src/thread_safe.h>

Public Types

enum class  overflow_policy_e { drop_oldest , reject }
 Behavior when raise() is called with the queue already at its bound. More...
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, overflow_policy_e overflow=overflow_policy_e::drop_oldest)
 Construct a bounded blocking queue.
template<class... Args>
bool raise (Args &&...args)
 Notify waiters that a new event value may be 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.

Member Enumeration Documentation

◆ overflow_policy_e

template<class T>
enum class safe::queue_t::overflow_policy_e
strong

Behavior when raise() is called with the queue already at its bound.

Enumerator
drop_oldest 

Clear the queue and accept the new item (current default behavior).

reject 

Refuse the new item, leaving existing queued items intact.

Constructor & Destructor Documentation

◆ queue_t()

template<class T>
safe::queue_t< T >::queue_t ( std::uint32_t max_elements = 32,
overflow_policy_e overflow = overflow_policy_e::drop_oldest )
inlineexplicit

Construct a bounded blocking queue.

Parameters
max_elementsMaximum number of elements that may be queued.
overflowBehavior when the queue reaches its maximum size.

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>
bool safe::queue_t< T >::raise ( Args &&... args)
inline

Notify waiters that a new event value may be available.

Parameters
argsArguments forwarded to the callable or parser.
Returns
True if the item was queued, false if the queue is stopped or the configured overflow policy rejects the item.

◆ 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: