SPH
|
Template for storing a copy of a value for every thread in given scheduler. More...
#include <ThreadLocal.h>
Classes | |
class | LocalIterator |
Public Member Functions | |
template<typename... TArgs> | |
ThreadLocal (IScheduler &scheduler, TArgs &&... args) | |
Constructs a thread-local storage from a list of values. More... | |
template<typename TFunctor > | |
ThreadLocal (IScheduler &scheduler, TFunctor &&functor) | |
Constructs a thread-local storage using a functor. More... | |
INLINE Type & | local () |
Return a value for current thread. More... | |
INLINE const Type & | local () const |
Return a value for current thread. More... | |
INLINE Type & | value (const Size threadId) |
Returns the storage corresponding to the thread with given index. More... | |
Type | accumulate (const Type &initial=Type(0._f)) const |
Performs an accumulation of thread-local values. More... | |
template<typename TPredicate > | |
Type | accumulate (const Type &initial, const TPredicate &predicate) const |
Performs an accumulation of thread-local values. More... | |
LocalIterator< Local > | begin () |
Returns the iterator to the first element in the thread-local storage. More... | |
LocalIterator< const Local > | begin () const |
Returns the iterator to the first element in the thread-local storage. More... | |
LocalIterator< Local > | end () |
Returns the iterator to the first element in the thread-local storage. More... | |
LocalIterator< const Local > | end () const |
Returns the iterator to the first element in the thread-local storage. More... | |
Friends | |
template<typename > | |
class | ThreadLocal |
Template for storing a copy of a value for every thread in given scheduler.
While C++ provides thread_local keyword for creating thread-local storages with static duration, ThreadLocal template can be used for local variables or (non-static) member variables of classes.
Definition at line 36 of file ThreadLocal.h.
|
inline |
Constructs a thread-local storage from a list of values.
scheduler | Scheduler associated with the object. |
args | List of parameters that are passed into the constructor of each thread-local storage. |
Definition at line 70 of file ThreadLocal.h.
|
inline |
Constructs a thread-local storage using a functor.
scheduler | Scheduler associated with the object. |
functor | Functor used to initialize each thread-local object. |
Definition at line 80 of file ThreadLocal.h.
|
inline |
Performs an accumulation of thread-local values.
Uses provided binary predicate to accumulate the values.
initial | Value to which the accumulated result is initialized. |
predicate | Callable object with signature Type operator()(const Type&, const Type&). |
Definition at line 123 of file ThreadLocal.h.
|
inline |
Performs an accumulation of thread-local values.
Uses operator + to sum up the elements.
initial | Value to which the accumulated result is initialized. |
Definition at line 113 of file ThreadLocal.h.
|
inline |
Returns the iterator to the first element in the thread-local storage.
Definition at line 145 of file ThreadLocal.h.
|
inline |
Returns the iterator to the first element in the thread-local storage.
Definition at line 150 of file ThreadLocal.h.
|
inline |
Returns the iterator to the first element in the thread-local storage.
Definition at line 155 of file ThreadLocal.h.
|
inline |
Returns the iterator to the first element in the thread-local storage.
Definition at line 160 of file ThreadLocal.h.
|
inline |
Return a value for current thread.
This thread must belong the the thread pool given in constructor, checked by assert.
Definition at line 88 of file ThreadLocal.h.
|
inline |
Return a value for current thread.
This thread must belong the the thread pool given in constructor, checked by assert.
Definition at line 95 of file ThreadLocal.h.
|
inline |
Returns the storage corresponding to the thread with given index.
Can be called from any thread. There is no synchronization, so accessing the storage from the associated worker at the same time might cause a race condition.
Definition at line 105 of file ThreadLocal.h.
Definition at line 39 of file ThreadLocal.h.