template class mrpt::containers::PerThreadDataHolder

Overview

Creates an instance of the data type T per requesting thread.

#include <mrpt/containers/PerThreadDataHolder.h>

template <class T>
class PerThreadDataHolder
{
public:
    // construction

    PerThreadDataHolder();
    PerThreadDataHolder(const PerThreadDataHolder<T>& o);
    PerThreadDataHolder(PerThreadDataHolder<T>&& o);

    // methods

    T& get();
    const T& get() const;
    void run_on_all(const std::function<void(T&)>& f);
    void clear();
    PerThreadDataHolder<T>& operator = (const PerThreadDataHolder<T>& o);
    PerThreadDataHolder<T>& operator = (PerThreadDataHolder<T>&& o);
};

Construction

PerThreadDataHolder(const PerThreadDataHolder<T>& o)

Copy the data, leave mutexes apart.

PerThreadDataHolder(PerThreadDataHolder<T>&& o)

Move the data, leave mutexes apart.

Methods

void run_on_all(const std::function<void(T&)>& f)

Note: you should define your own mutex for the part of the user data T that is read & writen from different threads.

PerThreadDataHolder<T>& operator = (const PerThreadDataHolder<T>& o)

Copy the data, leave mutexes apart.

PerThreadDataHolder<T>& operator = (PerThreadDataHolder<T>&& o)

Move the data, leave mutexes apart.