ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
G4UA::ThreadActionHolder< ActionType > Class Template Reference

A thread-local storage wrapper for the user actions. More...

#include <ThreadActionHolder.h>

Collaboration diagram for G4UA::ThreadActionHolder< ActionType >:

Public Types

using ThreadMapKey_t = std::thread::id
 
using ThreadMapVal_t = ActionType *
 
using ThreadMapHash_t = std::hash< ThreadMapKey_t >
 
using ThreadMap_t = tbb::concurrent_unordered_map< ThreadMapKey_t, ThreadMapVal_t, ThreadMapHash_t >
 
using const_iterator = typename ThreadMap_t::const_iterator
 

Public Member Functions

 ~ThreadActionHolder ()
 Destructor will clean up the thread-local storage. More...
 
ActionType * get ()
 Get the object of the current thread. More...
 
void set (std::unique_ptr< ActionType > action)
 Assign the object of the current thread. More...
 
const_iterator begin () const
 Constant-access iteration over the action map. More...
 
const_iterator end () const
 Constant-access iteration over the action map. More...
 

Private Attributes

ThreadMap_t m_threadMap
 The wrapped thread-local storage container. More...
 

Detailed Description

template<class ActionType>
class G4UA::ThreadActionHolder< ActionType >

A thread-local storage wrapper for the user actions.

This container is implemented as a wrapper for a concurrent map keyed by std thread ID. It is thus fully thread-safe (in theory).

The thread-local storage is cleared in the destructor for now, at least until TBB's concurrent containers support move semantics and unique_ptr.

Author
Steve Farrell Steve.nosp@m.n.Fa.nosp@m.rrell.nosp@m.@cer.nosp@m.n.ch

Definition at line 30 of file ThreadActionHolder.h.

Member Typedef Documentation

◆ const_iterator

template<class ActionType >
using G4UA::ThreadActionHolder< ActionType >::const_iterator = typename ThreadMap_t::const_iterator

Definition at line 43 of file ThreadActionHolder.h.

◆ ThreadMap_t

template<class ActionType >
using G4UA::ThreadActionHolder< ActionType >::ThreadMap_t = tbb::concurrent_unordered_map < ThreadMapKey_t, ThreadMapVal_t, ThreadMapHash_t >

Definition at line 40 of file ThreadActionHolder.h.

◆ ThreadMapHash_t

template<class ActionType >
using G4UA::ThreadActionHolder< ActionType >::ThreadMapHash_t = std::hash<ThreadMapKey_t>

Definition at line 38 of file ThreadActionHolder.h.

◆ ThreadMapKey_t

template<class ActionType >
using G4UA::ThreadActionHolder< ActionType >::ThreadMapKey_t = std::thread::id

Definition at line 35 of file ThreadActionHolder.h.

◆ ThreadMapVal_t

template<class ActionType >
using G4UA::ThreadActionHolder< ActionType >::ThreadMapVal_t = ActionType*

Definition at line 36 of file ThreadActionHolder.h.

Constructor & Destructor Documentation

◆ ~ThreadActionHolder()

template<class ActionType >
G4UA::ThreadActionHolder< ActionType >::~ThreadActionHolder ( )
inline

Destructor will clean up the thread-local storage.

Would prefer to do this automatically with unique_ptr.

Definition at line 47 of file ThreadActionHolder.h.

47  {
48  for(auto mapPair : m_threadMap){
49  delete mapPair.second;
50  }
51  m_threadMap.clear();
52  }

Member Function Documentation

◆ begin()

template<class ActionType >
const_iterator G4UA::ThreadActionHolder< ActionType >::begin ( ) const
inline

Constant-access iteration over the action map.

Definition at line 69 of file ThreadActionHolder.h.

69  {
70  return m_threadMap.begin();
71  }

◆ end()

template<class ActionType >
const_iterator G4UA::ThreadActionHolder< ActionType >::end ( ) const
inline

Constant-access iteration over the action map.

Definition at line 74 of file ThreadActionHolder.h.

74  {
75  return m_threadMap.end();
76  }

◆ get()

template<class ActionType >
ActionType* G4UA::ThreadActionHolder< ActionType >::get ( )
inline

Get the object of the current thread.

Definition at line 55 of file ThreadActionHolder.h.

55  {
56  auto mapPair = m_threadMap.find( std::this_thread::get_id() );
57  if(mapPair == m_threadMap.end()) return nullptr;
58  return mapPair->second;
59  }

◆ set()

template<class ActionType >
void G4UA::ThreadActionHolder< ActionType >::set ( std::unique_ptr< ActionType >  action)
inline

Assign the object of the current thread.

Memory management must be handled manually for now.

Definition at line 63 of file ThreadActionHolder.h.

63  {
64  const auto tid = std::this_thread::get_id();
65  m_threadMap.insert( std::make_pair(tid, action.release()) );
66  }

Member Data Documentation

◆ m_threadMap

template<class ActionType >
ThreadMap_t G4UA::ThreadActionHolder< ActionType >::m_threadMap
private

The wrapped thread-local storage container.

Definition at line 81 of file ThreadActionHolder.h.


The documentation for this class was generated from the following file:
G4UA::ThreadActionHolder::m_threadMap
ThreadMap_t m_threadMap
The wrapped thread-local storage container.
Definition: ThreadActionHolder.h:81
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77