A template for created thread-safe variables with an internal critical section controlled each read or write.
Example:
CThreadSafeVariable<double> var1;
...
var.set(2.3); // Sets the value
double x = var.get(); // Reads the variable
...
double foo = var; // Also reads the variable
var = 2.3; // ERROR: Not allowed, use ".set()" instead.
#include <mrpt/synch/CThreadSafeVariable.h>
Public Member Functions | |
| CThreadSafeVariable () | |
| CThreadSafeVariable (const T &init_val) | |
| virtual | ~CThreadSafeVariable () |
| T | get () const |
| Return a copy of the hold variable. | |
| void | get (T &out_val) const |
| Return a copy of the hold variable. | |
| operator T (void) const | |
| Return a copy of the hold variable. | |
| void | set (const T &new_val) |
| Return a copy of the hold variable. | |
| void | swap (T &in_out_var) |
| Swap the current value of the hold variable and the passed one, as one atomic operation. | |
Private Attributes | |
| CCriticalSection | m_cs |
| T | m_val |
| mrpt::synch::CThreadSafeVariable::CThreadSafeVariable | ( | ) | [inline] |
Definition at line 60 of file CThreadSafeVariable.h.
| mrpt::synch::CThreadSafeVariable::CThreadSafeVariable | ( | const T & | init_val | ) | [inline] |
Definition at line 61 of file CThreadSafeVariable.h.
| virtual mrpt::synch::CThreadSafeVariable::~CThreadSafeVariable | ( | ) | [inline, virtual] |
Definition at line 63 of file CThreadSafeVariable.h.
| T mrpt::synch::CThreadSafeVariable::get | ( | ) | const [inline] |
Return a copy of the hold variable.
Definition at line 66 of file CThreadSafeVariable.h.
| void mrpt::synch::CThreadSafeVariable::get | ( | T & | out_val | ) | const [inline] |
Return a copy of the hold variable.
Definition at line 77 of file CThreadSafeVariable.h.
| mrpt::synch::CThreadSafeVariable::operator T | ( | void | ) | const [inline] |
Return a copy of the hold variable.
Definition at line 84 of file CThreadSafeVariable.h.
| void mrpt::synch::CThreadSafeVariable::set | ( | const T & | new_val | ) | [inline] |
Return a copy of the hold variable.
Definition at line 91 of file CThreadSafeVariable.h.
| void mrpt::synch::CThreadSafeVariable::swap | ( | T & | in_out_var | ) | [inline] |
Swap the current value of the hold variable and the passed one, as one atomic operation.
Definition at line 98 of file CThreadSafeVariable.h.
Definition at line 57 of file CThreadSafeVariable.h.
Referenced by get(), operator T(), set(), and swap().
T mrpt::synch::CThreadSafeVariable::m_val [private] |
Definition at line 58 of file CThreadSafeVariable.h.
Referenced by get(), operator T(), set(), and swap().
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |