aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::ThreadData< T_DATA > Class Template Reference

A wrapper that enables to store data in a way that prevents false cacheline sharing. More...

#include <agrum/base/core/threads/threadData.h>

Public Types

using data_type = std::conditional< std::is_scalar< T_DATA >::value, T_DATA, T_DATA& >
 the return types of accessors: T_DATA if scalar, else T_DATA&

Public Member Functions

template<typename X>
std::enable_if_t< std::is_pointer< X >::value, typename ThreadData< T_DATA >::data_pointeroperator-> ()
template<typename X>
std::enable_if_t< !std::is_pointer< X >::value, typename ThreadData< T_DATA >::data_pointeroperator-> ()
Constructors / Destructors
 ThreadData (const T_DATA &theData)
 default constructor
 ThreadData (T_DATA &&theData)
 default constructor
 ThreadData (const ThreadData< T_DATA > &from)
 copy constructor
 ThreadData (ThreadData< T_DATA > &&from)
 move constructor
 ~ThreadData ()=default
 destructor
Operators
ThreadData< T_DATA > & operator= (const ThreadData< T_DATA > &from)
 copy operator
ThreadData< T_DATA > & operator= (ThreadData< T_DATA > &&from)
 move operator
bool operator== (const ThreadData< T_DATA > &from) const
 equality operator
bool operator== (const T_DATA &from) const
 equality operator
bool operator!= (const ThreadData< T_DATA > &from) const
 inequality operator
bool operator!= (const T_DATA &from) const
 inequality operator

Accessors

using data_pointer
 the data we wish to store without cacheline parallel problem
T_DATA data
 the data we wish to store without cacheline parallel problem
data_type operator* ()
 easy accessor
template<typename X = T_DATA>
std::enable_if_t< std::is_pointer< X >::value, data_pointeroperator-> ()
 the data we wish to store without cacheline parallel problem
template<typename X = T_DATA>
std::enable_if_t< !std::is_pointer< X >::value, data_pointeroperator-> ()
 the data we wish to store without cacheline parallel problem

Detailed Description

template<typename T_DATA>
class gum::ThreadData< T_DATA >

A wrapper that enables to store data in a way that prevents false cacheline sharing.

When several threads access to some shared containers like vectors, it may be the case that they access some data within these containers that are too close, which results in false sharing of the cacheline. By wrapping the data into a ThreadData, we guarantee that no false sharing can occur.

To create a wrapper data, simply use wrapped_data = ThreadData (data) and To get the data wrapped, use wrapped_data.data;

Definition at line 77 of file threadData.h.

Member Typedef Documentation

◆ data_pointer

template<typename T_DATA>
using gum::ThreadData< T_DATA >::data_pointer
Initial value:
typename std::conditional< std::is_pointer< T_DATA >::value,
T_DATA,
typename std::add_pointer< T_DATA >::type >::type

the data we wish to store without cacheline parallel problem

Definition at line 138 of file threadData.h.

◆ data_type

template<typename T_DATA>
using gum::ThreadData< T_DATA >::data_type = std::conditional< std::is_scalar< T_DATA >::value, T_DATA, T_DATA& >

the return types of accessors: T_DATA if scalar, else T_DATA&

Definition at line 79 of file threadData.h.

Constructor & Destructor Documentation

◆ ThreadData() [1/4]

template<typename T_DATA>
gum::ThreadData< T_DATA >::ThreadData ( const T_DATA & theData)

default constructor

Definition at line 49 of file threadData_inl.h.

49: data(theData) {}
A wrapper that enables to store data in a way that prevents false cacheline sharing.
Definition threadData.h:77
T_DATA data
the data we wish to store without cacheline parallel problem
Definition threadData.h:150

References data.

Referenced by ThreadData(), ThreadData(), ~ThreadData(), operator!=(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ ThreadData() [2/4]

template<typename T_DATA>
gum::ThreadData< T_DATA >::ThreadData ( T_DATA && theData)

default constructor

Definition at line 52 of file threadData_inl.h.

References data.

◆ ThreadData() [3/4]

template<typename T_DATA>
gum::ThreadData< T_DATA >::ThreadData ( const ThreadData< T_DATA > & from)

copy constructor

Definition at line 55 of file threadData_inl.h.

55: data(from.data) {}

References ThreadData(), and data.

Here is the call graph for this function:

◆ ThreadData() [4/4]

template<typename T_DATA>
gum::ThreadData< T_DATA >::ThreadData ( ThreadData< T_DATA > && from)

move constructor

Definition at line 58 of file threadData_inl.h.

58 :

References ThreadData(), and data.

Here is the call graph for this function:

◆ ~ThreadData()

template<typename T_DATA>
gum::ThreadData< T_DATA >::~ThreadData ( )
default

destructor

References ThreadData().

Here is the call graph for this function:

Member Function Documentation

◆ operator!=() [1/2]

template<typename T_DATA>
bool gum::ThreadData< T_DATA >::operator!= ( const T_DATA & from) const

inequality operator

Definition at line 89 of file threadData_inl.h.

89 {
90 return data != from;
91 }

References data.

◆ operator!=() [2/2]

template<typename T_DATA>
bool gum::ThreadData< T_DATA >::operator!= ( const ThreadData< T_DATA > & from) const

inequality operator

Definition at line 84 of file threadData_inl.h.

84 {
85 return data != from.data;
86 }

References ThreadData(), and data.

Here is the call graph for this function:

◆ operator*()

template<typename T_DATA>
ThreadData< T_DATA >::data_type gum::ThreadData< T_DATA >::operator* ( )

easy accessor

Definition at line 94 of file threadData_inl.h.

94 {
95 return data;
96 }

References data.

◆ operator->() [1/4]

template<typename T_DATA>
template<typename X = T_DATA>
std::enable_if_t< !std::is_pointer< X >::value, data_pointer > gum::ThreadData< T_DATA >::operator-> ( )

the data we wish to store without cacheline parallel problem

◆ operator->() [2/4]

template<typename T_DATA>
template<typename X = T_DATA>
std::enable_if_t< std::is_pointer< X >::value, data_pointer > gum::ThreadData< T_DATA >::operator-> ( )

the data we wish to store without cacheline parallel problem

Referenced by operator->().

Here is the caller graph for this function:

◆ operator->() [3/4]

template<typename T_DATA>
template<typename X>
std::enable_if_t< !std::is_pointer< X >::value, typename ThreadData< T_DATA >::data_pointer > gum::ThreadData< T_DATA >::operator-> ( )

Definition at line 104 of file threadData_tpl.h.

104 {
105 return &data;
106 }

References data, and operator->().

Here is the call graph for this function:

◆ operator->() [4/4]

template<typename T_DATA>
template<typename X>
std::enable_if_t< std::is_pointer< X >::value, typename ThreadData< T_DATA >::data_pointer > gum::ThreadData< T_DATA >::operator-> ( )

Definition at line 97 of file threadData_tpl.h.

97 {
98 return data;
99 }

References data, and operator->().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename T_DATA>
ThreadData< T_DATA > & gum::ThreadData< T_DATA >::operator= ( const ThreadData< T_DATA > & from)
default

copy operator

Definition at line 62 of file threadData_inl.h.

62 {
63 data = from.data;
64 return *this;
65 }

References ThreadData(), and data.

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename T_DATA>
ThreadData< T_DATA > & gum::ThreadData< T_DATA >::operator= ( ThreadData< T_DATA > && from)

move operator

Definition at line 68 of file threadData_inl.h.

68 {
70 return *this;
71 }

References ThreadData(), and data.

Here is the call graph for this function:

◆ operator==() [1/2]

template<typename T_DATA>
bool gum::ThreadData< T_DATA >::operator== ( const T_DATA & from) const

equality operator

Definition at line 79 of file threadData_inl.h.

79 {
80 return data == from;
81 }

References data.

◆ operator==() [2/2]

template<typename T_DATA>
bool gum::ThreadData< T_DATA >::operator== ( const ThreadData< T_DATA > & from) const

equality operator

Definition at line 74 of file threadData_inl.h.

74 {
75 return data == from.data;
76 }

References ThreadData(), and data.

Here is the call graph for this function:

Member Data Documentation

◆ data

template<typename T_DATA>
T_DATA gum::ThreadData< T_DATA >::data

the data we wish to store without cacheline parallel problem

Definition at line 150 of file threadData.h.

Referenced by ThreadData(), ThreadData(), ThreadData(), ThreadData(), operator!=(), operator!=(), operator*(), operator->(), operator=(), operator=(), operator==(), and operator==().


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