trikRuntime
trikKernel::SynchronizedVar< T > Class Template Reference

Helper template for syncing reader and writer. More...

#include <synchronizedVar.h>

Public Member Functions

 SynchronizedVar ()
 Constructor. Creates var with default buffer and value. More...
 
get ()
 Returns synced value. May be called from reader thread. More...
 
T * operator-> ()
 Returns pointer to unsynced buffer. More...
 
const T & operator* () const
 Returns contents of unsynced buffer. More...
 
void sync ()
 Copies value from buffer to synced value, invalidates buffer. More...
 
void reset ()
 Resets buffer to initial state. More...
 

Detailed Description

template<typename T>
class trikKernel::SynchronizedVar< T >

Helper template for syncing reader and writer.

Compound value can be written to buffer using "->" operator, then, when "sync" is called, it is swapped with current value, which can be accessed using "get". For example, SynchronizedVar<Point> var; var->x = 10; var.sync(); var->x = 20; EXPECT_EQ(10, var.get().x); var.sync(); EXPECT_EQ(20, var.get().x);

Constructor & Destructor Documentation

template<typename T>
trikKernel::SynchronizedVar< T >::SynchronizedVar ( )
inline

Constructor. Creates var with default buffer and value.

Member Function Documentation

template<typename T>
T trikKernel::SynchronizedVar< T >::get ( )
inline

Returns synced value. May be called from reader thread.

template<typename T>
const T& trikKernel::SynchronizedVar< T >::operator* ( ) const
inline

Returns contents of unsynced buffer.

Shall be called only from writer thread.

template<typename T>
T* trikKernel::SynchronizedVar< T >::operator-> ( )
inline

Returns pointer to unsynced buffer.

Shall be called only from writer thread.

template<typename T>
void trikKernel::SynchronizedVar< T >::reset ( )
inline

Resets buffer to initial state.

Shall be called from writer thread.

template<typename T>
void trikKernel::SynchronizedVar< T >::sync ( )
inline

Copies value from buffer to synced value, invalidates buffer.

Shall be called from writer thread.


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