Class real_time_tools::SingletypeThreadsafeObject

template<typename Type, size_t SIZE>
class real_time_tools::SingletypeThreadsafeObject

The SingletypeThreadsafeObject is a thread safe object.

tparam Type

is the data type to store in the buffer.

tparam SIZE

is the size of the buffer. It is better to know it at compile time to be 100% real time safe.

Public Functions

SingletypeThreadsafeObject()

Construct a new SingletypeThreadsafeObject object.

SingletypeThreadsafeObject(const std::vector<std::string> &names)

Construct a new SingletypeThreadsafeObject object.

Parameters

names

void wait_for_update(const size_t &index) const

Wait until the data at the given index is modified.

Parameters

index

inline void wait_for_update(const std::string &name) const

Wait until the data at the given name is modified.

Parameters

name

size_t wait_for_update() const

Wait unitl any data has been changed and return its index.

Returns

size_t

inline size_t size()

Getters.

get size.

Returns

size_t

inline Type get(const size_t &index = 0) const

Get the data by its index in the buffer.

Parameters

index

Returns

Type

inline Type get(const std::string &name) const

Get the data by its name in the buffer.

Parameters

name

Returns

Type

template<int INDEX = 0>
inline Type get() const

Get the data by its index in the buffer.

Index is solved during compile time

Template Parameters

INDEX=0

Returns

Type

void set(const Type &datum, const size_t &index = 0)

Setters.

Set one element at a designated index.

Parameters
  • datum

  • index

template<int INDEX = 0>
inline void set(Type datum)

Set one element at a designated index.

Warning the index is resolved at compile time. This is used for backward comaptibility.

Todo:

”This is used for backward comaptibility.”, Manuel Which bakward?

Template Parameters

INDEX=0

Parameters

datum

inline void set(const Type &datum, const std::string &name)

Set one element using at a designated name.

Internally this name is map to an index.

Parameters
  • datum

  • name

Private Members

std::shared_ptr<std::array<Type, SIZE>> data_

This is the data buffer.

std::shared_ptr<std::array<size_t, SIZE>> modification_counts_

This is counting the data modification occurences for each individual buffers.

std::shared_ptr<size_t> total_modification_count_

This is counting the all data modification occurences for all buffer.

/todo Can’t we just some the modification_counts_ array whenever needed?

std::map<std::string, size_t> name_to_index_

This is the map that allow to deal with data by their names.

mutable std::shared_ptr<std::condition_variable> condition_

This condition variable is used to wait untils any data has been changed.

mutable std::shared_ptr<std::mutex> condition_mutex_

This is the mutex of the condition varaible.

mutable std::shared_ptr<std::array<std::mutex, SIZE>> data_mutexes_

These are the individual mutexes of each data upon setting and getting.