Sunshine master
Self-hosted game stream host for Moonlight.
thread_safe.h File Reference

Declarations for thread-safe data structures. More...

#include <array>
#include <atomic>
#include <condition_variable>
#include <functional>
#include <map>
#include <mutex>
#include <vector>
#include "utility.h"
Include dependency graph for thread_safe.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  safe::alarm_raw_t< T >
 Alarm primitive used to wait for and raise shutdown-style signals. More...
 
class  safe::event_t< T >
 Thread-safe event value that blocks readers until a value is raised. More...
 
class  safe::mail_raw_t
 Mailbox backing store for events, queues, and posted cleanup objects. More...
 
class  safe::post_t< T >
 Wrapper that posts cleanup work to a mailbox when destroyed. More...
 
struct  safe::shared_t< T >::ptr_t
 Pointer wrapper state protected by synchronization. More...
 
class  safe::queue_t< T >
 Thread-safe queue with blocking and shutdown-aware consumers. More...
 
class  safe::shared_t< T >
 Shared object storage with custom construction and destruction hooks. More...
 

Typedefs

template<class T >
using safe::alarm_t = std::shared_ptr<alarm_raw_t<T>>
 Shared alarm primitive used for cross-thread shutdown signals.
 
using safe::mail_t = std::shared_ptr<mail_raw_t>
 Shared mailbox handle used by event and queue wrappers.
 
using safe::signal_t = event_t<bool>
 Boolean alarm used as a simple signal.
 

Functions

void safe::cleanup (mail_raw_t *)
 Run cleanup for completed asynchronous work.
 
template<class T >
auto safe::lock (const std::weak_ptr< void > &wp)
 Acquire the underlying lock or keyed mutex.
 
template<class T >
alarm_t< T > safe::make_alarm ()
 Create a alarm object or message.
 
template<class T , class F_Construct , class F_Destruct >
auto safe::make_shared (F_Construct &&fc, F_Destruct &&fd)
 Create a shared object or message.
 

Detailed Description

Declarations for thread-safe data structures.

Function Documentation

◆ cleanup()

void safe::cleanup ( mail_raw_t * mail)
inline

Run cleanup for completed asynchronous work.

Parameters
mailMailbox used to exchange messages with worker threads.

◆ lock()

template<class T >
auto safe::lock ( const std::weak_ptr< void > & wp)
inline

Acquire the underlying lock or keyed mutex.

Parameters
wpWeak pointer used to test whether the object is still alive.
Returns
Lock guard owning the synchronized object until destruction.

◆ make_alarm()

template<class T >
alarm_t< T > safe::make_alarm ( )

Create a alarm object or message.

Returns
Constructed alarm object.

◆ make_shared()

template<class T , class F_Construct , class F_Destruct >
auto safe::make_shared ( F_Construct && fc,
F_Destruct && fd )

Create a shared object or message.

Parameters
fcCallable executed while the shared object is locked.
fdNative file descriptor to wrap or inspect.
Returns
Constructed shared object.