SuperTuxKart
Loading...
Searching...
No Matches
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.
 
 Synchronised (const TYPE &v)
 Initialise the data and the mutex.
 
 ~Synchronised ()
 Destroy this mutex.
 
void setAtomic (const TYPE &v)
 Sets the value of this variable using a mutex.
 
TYPE getAtomic () const
 Returns a copy of this variable.
 
TYPE & getData ()
 Returns a reference to the original data file.
 
const TYPE & getData () const
 
void lock () const
 Locks the mutex.
 
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.
 

Private Member Functions

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

Private Attributes

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

Detailed Description

template<typename TYPE>
class Synchronised< TYPE >

A variable that is automatically synchronised using pthreads mutex.

Member Function Documentation

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

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