Sunshine master
Self-hosted game stream host for Moonlight.
sync_util::sync_t< T, M > Class Template Reference

Value wrapper that pairs an object with the mutex protecting it. More...

#include <src/sync.h>

Public Types

using mutex_t = M
 Mutex type used to protect the stored value.
 
using value_t = T
 Type stored behind the synchronization wrapper.
 

Public Member Functions

std::lock_guard< mutex_tlock ()
 Acquire the underlying lock or keyed mutex.
 
value_toperator* ()
 Dereference the protected value.
 
const value_toperator* () const
 Dereference the protected value.
 
value_toperator-> ()
 Access the protected value directly.
 
sync_toperator= (const value_t &val) noexcept
 Copy-assign the protected value while holding this wrapper's lock.
 
sync_toperator= (sync_t &&other) noexcept
 Move another synchronized value into this instance while locking both wrappers.
 
sync_toperator= (sync_t &other) noexcept
 Copy another synchronized value into this instance while locking both wrappers.
 
template<class V >
sync_toperator= (V &&val)
 Assign a new value while holding this wrapper's lock.
 
sync_toperator= (value_t &&val) noexcept
 Move-assign the protected value while holding this wrapper's lock.
 
template<class... Args>
 sync_t (Args &&...args)
 Initialize the protected object from forwarded arguments.
 

Public Attributes

value_t raw
 Protected value accessed while this helper's lock is held.
 

Detailed Description

template<class T, class M = std::mutex>
class sync_util::sync_t< T, M >

Value wrapper that pairs an object with the mutex protecting it.

Constructor & Destructor Documentation

◆ sync_t()

template<class T , class M = std::mutex>
template<class... Args>
sync_util::sync_t< T, M >::sync_t ( Args &&... args)
inline

Initialize the protected object from forwarded arguments.

Parameters
argsArguments forwarded to the protected object's constructor.

Member Function Documentation

◆ lock()

template<class T , class M = std::mutex>
std::lock_guard< mutex_t > sync_util::sync_t< T, M >::lock ( )
inline

Acquire the underlying lock or keyed mutex.

Returns
Lock guard owning the synchronized object until destruction.

◆ operator*() [1/2]

template<class T , class M = std::mutex>
value_t & sync_util::sync_t< T, M >::operator* ( )
inline

Dereference the protected value.

Returns
Mutable reference to the protected value.

◆ operator*() [2/2]

template<class T , class M = std::mutex>
const value_t & sync_util::sync_t< T, M >::operator* ( ) const
inline

Dereference the protected value.

Returns
Const reference to the protected value.

◆ operator->()

template<class T , class M = std::mutex>
value_t * sync_util::sync_t< T, M >::operator-> ( )
inline

Access the protected value directly.

Returns
Pointer to the protected value.

◆ operator=() [1/5]

template<class T , class M = std::mutex>
sync_t & sync_util::sync_t< T, M >::operator= ( const value_t & val)
inlinenoexcept

Copy-assign the protected value while holding this wrapper's lock.

Parameters
valValue assigned to the synchronized object.
Returns
Reference to this wrapper.

◆ operator=() [2/5]

template<class T , class M = std::mutex>
sync_t & sync_util::sync_t< T, M >::operator= ( sync_t< T, M > && other)
inlinenoexcept

Move another synchronized value into this instance while locking both wrappers.

Parameters
otherSource object whose state is copied or moved into this object.
Returns
Reference to this wrapper.

◆ operator=() [3/5]

template<class T , class M = std::mutex>
sync_t & sync_util::sync_t< T, M >::operator= ( sync_t< T, M > & other)
inlinenoexcept

Copy another synchronized value into this instance while locking both wrappers.

Parameters
otherSource object whose state is copied or moved into this object.
Returns
Reference to this wrapper.

◆ operator=() [4/5]

template<class T , class M = std::mutex>
template<class V >
sync_t & sync_util::sync_t< T, M >::operator= ( V && val)
inline

Assign a new value while holding this wrapper's lock.

Parameters
valValue assigned to the synchronized object.
Returns
Reference to this wrapper.

◆ operator=() [5/5]

template<class T , class M = std::mutex>
sync_t & sync_util::sync_t< T, M >::operator= ( value_t && val)
inlinenoexcept

Move-assign the protected value while holding this wrapper's lock.

Parameters
valValue assigned to the synchronized object.
Returns
Reference to this wrapper.

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