SuperTuxKart
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Synchronised< TYPE > Class Template Reference

A variable that is automatically synchronised using pthreads mutex. More...

#include <synchronised.hpp>

Public Member Functions

 Synchronised ()
 Initialise the data and the mutex with default constructors. More...
 
 Synchronised (const TYPE &v)
 Initialise the data and the mutex. More...
 
 ~Synchronised ()
 Destroy this mutex.
 
void setAtomic (const TYPE &v)
 Sets the value of this variable using a mutex. More...
 
TYPE getAtomic () const
 Returns a copy of this variable.
 
TYPE & getData ()
 Returns a reference to the original data file. More...
 
const TYPE & getData () const
 
void lock () const
 Locks the mutex. More...
 
void unlock () const
 Unlocks the mutex.
 
std::unique_lock< std::mutex > acquireMutex () const
 Gives unique_lock to the mutex, which can then be used by std::condition_variable wait. More...
 

Private Member Functions

void operator= (const Synchronised< TYPE > &v)
 

Private Attributes

std::mutex m_mutex
 The mutex to protect this variable with. More...
 
TYPE m_data
 The actual data to be used. More...
 

Detailed Description

template<typename TYPE>
class Synchronised< TYPE >

A variable that is automatically synchronised using pthreads mutex.

Constructor & Destructor Documentation

◆ Synchronised() [1/2]

template<typename TYPE>
Synchronised< TYPE >::Synchronised ( )
inline

Initialise the data and the mutex with default constructors.

◆ Synchronised() [2/2]

template<typename TYPE>
Synchronised< TYPE >::Synchronised ( const TYPE &  v)
inline

Initialise the data and the mutex.

Member Function Documentation

◆ acquireMutex()

template<typename TYPE>
std::unique_lock<std::mutex> Synchronised< TYPE >::acquireMutex ( ) const
inline

Gives unique_lock to the mutex, which can then be used by std::condition_variable wait.

◆ getData()

template<typename TYPE>
TYPE& Synchronised< TYPE >::getData ( )
inline

Returns a reference to the original data file.

NOTE: all access to the data files happen without mutex protection, so calls to lock and unlock are necessary. This method is useful in cases that several operations on the class must happen atomic.

◆ lock()

template<typename TYPE>
void Synchronised< TYPE >::lock ( ) const
inline

Locks the mutex.

Note that calls to get() or set() will fail, since they will try to lock the mutex as well!

◆ setAtomic()

template<typename TYPE>
void Synchronised< TYPE >::setAtomic ( const TYPE &  v)
inline

Sets the value of this variable using a mutex.

Parameters
vValue to be set.

Member Data Documentation

◆ m_data

template<typename TYPE>
TYPE Synchronised< TYPE >::m_data
private

The actual data to be used.

◆ m_mutex

template<typename TYPE>
std::mutex Synchronised< TYPE >::m_mutex
mutableprivate

The mutex to protect this variable with.


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