5#ifndef G4ATLASTOOLS_THREADSPECIFICUSERACTION_H
6#define G4ATLASTOOLS_THREADSPECIFICUSERACTION_H
14#include "tbb/concurrent_unordered_map.h"
29 template<
class ActionType>
47 delete mapPair.second;
54 auto mapItr =
m_threadMap.find( std::this_thread::get_id() );
56 return mapItr->second;
61 void set(std::unique_ptr<ActionType> action) {
62 const auto tid = std::this_thread::get_id();
63 m_threadMap.insert( std::make_pair(tid, action.release()) );
87 template<
class ResultType,
class Mapper,
class Reducer >
92 std::function<
const ResultType&(
const ActionType&)> mapper = mapOp;
93 std::function<void(ResultType&,
const ResultType&)> reducer = reduceOp;
96 reducer(
result, mapper(*keyVal.second) );
A thread-local storage wrapper for the user actions.
const_iterator end() const
Constant-access iteration over the action map.
std::thread::id ThreadMapKey_t
ActionType * ThreadMapVal_t
typename ThreadMap_t::const_iterator const_iterator
std::hash< ThreadMapKey_t > ThreadMapHash_t
void set(std::unique_ptr< ActionType > action)
Assign the object of the current thread.
ThreadMap_t m_threadMap
The wrapped thread-local storage container.
ActionType * get()
Get the object of the current thread.
~ThreadSpecificUserAction()
Destructor will clean up the thread-local storage.
tbb::concurrent_unordered_map< ThreadMapKey_t, ThreadMapVal_t, ThreadMapHash_t > ThreadMap_t
const_iterator begin() const
Constant-access iteration over the action map.
void accumulate(ResultType &result, Mapper mapOp, Reducer reduceOp)
Accumulate results across user actions with specified operations.