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

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

Definition at line 41 of file CThreadSafeVariable.h.

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

Definition at line 42 of file CThreadSafeVariable.h.

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

Definition at line 44 of file CThreadSafeVariable.h.

Member Function Documentation

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.

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.

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.

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.

Referenced by thread_DNS_solver_async().

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

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



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018