A variable that is automatically synchronised using pthreads mutex.
More...
#include <synchronised.hpp>
|
| 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.
|
|
|
std::mutex | m_mutex |
| The mutex to protect this variable with.
|
|
TYPE | m_data |
| The actual data to be used.
|
|
template<typename TYPE>
class Synchronised< TYPE >
A variable that is automatically synchronised using pthreads mutex.
◆ getData()
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()
Locks the mutex.
Note that calls to get() or set() will fail, since they will try to lock the mutex as well!
◆ setAtomic()
Sets the value of this variable using a mutex.
- Parameters
-
The documentation for this class was generated from the following file: