Main MRPT website > C++ reference for MRPT 1.5.6
List of all members | Public Member Functions | Private Attributes
mrpt::synch::CThreadSafeVariable< T > Class Template Reference

Detailed Description

template<typename T>
class mrpt::synch::CThreadSafeVariable< T >

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.
See also
CCriticalSection

Definition at line 35 of file CThreadSafeVariable.h.

#include <mrpt/synch/CThreadSafeVariable.h>

Inheritance diagram for mrpt::synch::CThreadSafeVariable< T >:
Inheritance graph

Public Member Functions

 CThreadSafeVariable ()
 
 CThreadSafeVariable (const T &init_val)
 
virtual ~CThreadSafeVariable ()
 
get () const
 Return a copy of the hold variable. More...
 
void get (T &out_val) const
 Return a copy of the hold variable. More...
 
 operator T (void) const
 Return a copy of the hold variable. More...
 
void set (const T &new_val)
 Return a copy of the hold variable. More...
 
void swap (T &in_out_var)
 Swap the current value of the hold variable and the passed one, as one atomic operation. More...
 

Private Attributes

CCriticalSection m_cs
 
m_val
 

Constructor & Destructor Documentation

◆ CThreadSafeVariable() [1/2]

template<typename T>
mrpt::synch::CThreadSafeVariable< T >::CThreadSafeVariable ( )
inline

Definition at line 41 of file CThreadSafeVariable.h.

◆ CThreadSafeVariable() [2/2]

template<typename T>
mrpt::synch::CThreadSafeVariable< T >::CThreadSafeVariable ( const T &  init_val)
inline

Definition at line 42 of file CThreadSafeVariable.h.

◆ ~CThreadSafeVariable()

template<typename T>
virtual mrpt::synch::CThreadSafeVariable< T >::~CThreadSafeVariable ( )
inlinevirtual

Definition at line 44 of file CThreadSafeVariable.h.

Member Function Documentation

◆ get() [1/2]

template<typename T>
T mrpt::synch::CThreadSafeVariable< T >::get ( ) const
inline

Return a copy of the hold variable.

Definition at line 47 of file CThreadSafeVariable.h.

◆ get() [2/2]

template<typename T>
void mrpt::synch::CThreadSafeVariable< T >::get ( T &  out_val) const
inline

Return a copy of the hold variable.

Definition at line 58 of file CThreadSafeVariable.h.

◆ operator T()

template<typename T>
mrpt::synch::CThreadSafeVariable< T >::operator T ( void  ) const
inline

Return a copy of the hold variable.

Definition at line 65 of file CThreadSafeVariable.h.

References mrpt::synch::CThreadSafeVariable< T >::m_cs, and mrpt::synch::CThreadSafeVariable< T >::m_val.

◆ set()

template<typename T>
void mrpt::synch::CThreadSafeVariable< T >::set ( const T &  new_val)
inline

Return a copy of the hold variable.

Definition at line 72 of file CThreadSafeVariable.h.

◆ swap()

template<typename T>
void mrpt::synch::CThreadSafeVariable< T >::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 79 of file CThreadSafeVariable.h.

Member Data Documentation

◆ m_cs

template<typename T>
CCriticalSection mrpt::synch::CThreadSafeVariable< T >::m_cs
private

◆ m_val

template<typename T>
T mrpt::synch::CThreadSafeVariable< T >::m_val
private



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019