RobWorkProject  24.5.15-
Public Member Functions | List of all members
ThreadSafeVariable< T > Class Template Reference

A thread safe protected variable. More...

#include <ThreadSafeVariable.hpp>

Public Member Functions

 ThreadSafeVariable (const T var)
 Create new protected variable. More...
 
virtual ~ThreadSafeVariable ()
 Destructor.
 
getVariable ()
 Get the value. More...
 
void setVariable (const T var)
 Change the value. More...
 
waitForUpdate (T previous)
 Wait for a change of the value (blocking). More...
 
operator() ()
 Use the () operator to access the value. More...
 
void operator= (const T var)
 Set the value using the assignment operator (same as using setVariable()). More...
 

Detailed Description

template<typename T>
class rw::common::ThreadSafeVariable< T >

A thread safe protected variable.

This is very useful for making simple thread-safe variables, but also for synchronization between threads.

Constructor & Destructor Documentation

◆ ThreadSafeVariable()

ThreadSafeVariable ( const T  var)
inline

Create new protected variable.

Parameters
var[in] the initial value.

Member Function Documentation

◆ getVariable()

T getVariable ( )
inline

Get the value.

Returns
the value.

◆ operator()()

T operator() ( )
inline

Use the () operator to access the value.

Returns
the value.

◆ operator=()

void operator= ( const T  var)
inline

Set the value using the assignment operator (same as using setVariable()).

Parameters
var[in] the new value.

◆ setVariable()

void setVariable ( const T  var)
inline

Change the value.

Note
If some are still waiting for the last update of the value (by using the waitForUpdate() function), this function will block until they have received the previous update first.
Parameters
var[in] the new value.

◆ waitForUpdate()

T waitForUpdate ( previous)
inline

Wait for a change of the value (blocking).

Parameters
previous[in] the previous value to compare with.
Note
The type, T, should implement the operator== function for comparison.
Returns
the new value that is not equal to the previous value.

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