ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Atlas
G4AtlasTools
G4AtlasTools
ThreadActionHolder.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef G4ATLASTOOLS__G4UA_THREADACTIONHOLDER_H
6
#define G4ATLASTOOLS__G4UA_THREADACTIONHOLDER_H
7
8
// System includes
9
#include <thread>
10
#include <memory>
11
#include <utility>
12
13
// Other includes
14
#include "tbb/concurrent_unordered_map.h"
15
16
namespace
G4UA
17
{
18
29
template
<
class
ActionType>
30
class
ThreadActionHolder
31
{
32
33
public
:
34
35
using
ThreadMapKey_t
= std::thread::id;
36
using
ThreadMapVal_t
= ActionType*;
37
//using ThreadMapVal_t = std::unique_ptr<ActionType>; // not supported
38
using
ThreadMapHash_t
= std::hash<ThreadMapKey_t>;
39
40
using
ThreadMap_t
= tbb::concurrent_unordered_map
41
<
ThreadMapKey_t
,
ThreadMapVal_t
,
ThreadMapHash_t
>;
42
43
using
const_iterator
=
typename
ThreadMap_t::const_iterator;
44
47
~ThreadActionHolder
() {
48
for
(
auto
mapPair :
m_threadMap
){
49
delete
mapPair.second;
50
}
51
m_threadMap
.clear();
52
}
53
55
ActionType*
get
() {
56
auto
mapPair =
m_threadMap
.find( std::this_thread::get_id() );
57
if
(mapPair ==
m_threadMap
.end())
return
nullptr
;
58
return
mapPair->second;
59
}
60
63
void
set
(std::unique_ptr<ActionType> action) {
64
const
auto
tid = std::this_thread::get_id();
65
m_threadMap
.insert( std::make_pair(tid, action.release()) );
66
}
67
69
const_iterator
begin
()
const
{
70
return
m_threadMap
.begin();
71
}
72
74
const_iterator
end
()
const
{
75
return
m_threadMap
.end();
76
}
77
78
private
:
79
81
ThreadMap_t
m_threadMap
;
82
83
};
// class ThreadActionHolder
84
85
}
86
87
#endif
G4UA::ThreadActionHolder
A thread-local storage wrapper for the user actions.
Definition
ThreadActionHolder.h:31
G4UA::ThreadActionHolder::ThreadMap_t
tbb::concurrent_unordered_map< ThreadMapKey_t, ThreadMapVal_t, ThreadMapHash_t > ThreadMap_t
Definition
ThreadActionHolder.h:40
G4UA::ThreadActionHolder::end
const_iterator end() const
Constant-access iteration over the action map.
Definition
ThreadActionHolder.h:74
G4UA::ThreadActionHolder::ThreadMapVal_t
ActionType * ThreadMapVal_t
Definition
ThreadActionHolder.h:36
G4UA::ThreadActionHolder::ThreadMapHash_t
std::hash< ThreadMapKey_t > ThreadMapHash_t
Definition
ThreadActionHolder.h:38
G4UA::ThreadActionHolder::set
void set(std::unique_ptr< ActionType > action)
Assign the object of the current thread.
Definition
ThreadActionHolder.h:63
G4UA::ThreadActionHolder::ThreadMapKey_t
std::thread::id ThreadMapKey_t
Definition
ThreadActionHolder.h:35
G4UA::ThreadActionHolder::const_iterator
typename ThreadMap_t::const_iterator const_iterator
Definition
ThreadActionHolder.h:43
G4UA::ThreadActionHolder::begin
const_iterator begin() const
Constant-access iteration over the action map.
Definition
ThreadActionHolder.h:69
G4UA::ThreadActionHolder::m_threadMap
ThreadMap_t m_threadMap
The wrapped thread-local storage container.
Definition
ThreadActionHolder.h:81
G4UA::ThreadActionHolder::get
ActionType * get()
Get the object of the current thread.
Definition
ThreadActionHolder.h:55
G4UA::ThreadActionHolder::~ThreadActionHolder
~ThreadActionHolder()
Destructor will clean up the thread-local storage.
Definition
ThreadActionHolder.h:47
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
Generated on
for ATLAS Offline Software by
1.17.0