-
Notifications
You must be signed in to change notification settings - Fork 180
/
heppdt-3.03.00-concurrency.patch
80 lines (70 loc) · 2.67 KB
/
heppdt-3.03.00-concurrency.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff -x Makefile -x '*.Po' -ur a/include/HepPDT/ParticleDataTable.hh b/include/HepPDT/ParticleDataTable.hh
--- a/include/HepPDT/ParticleDataTable.hh 2008-10-14 12:36:40.000000000 -0400
+++ b/include/HepPDT/ParticleDataTable.hh 2016-01-28 14:05:21.407152947 -0500
@@ -10,6 +10,7 @@
#include <iostream>
#include <string>
#include <map>
+#include "tbb/concurrent_unordered_map.h"
#include "HepPDT/ParticleID.hh"
#include "HepPDT/ParticleData.hh"
@@ -44,11 +45,19 @@
class ParticleDataTable {
public:
+ struct PIDhash {
+ PIDhash() {}
+ size_t operator()(const ParticleID& p) const
+ {
+ return tbb::tbb_hasher(p.pid());
+ }
+ };
+
typedef ParticleData CPD;
typedef std::map<ParticleID,TempParticleData> TempMap;
- typedef std::map<ParticleID,ParticleData,ParticleDataTableComparison> PDTMap;
- typedef std::map<std::string,ParticleID> PDTNameMap;
+ typedef tbb::concurrent_unordered_map<ParticleID,ParticleData,PIDhash> PDTMap;
+ typedef tbb::concurrent_unordered_map<std::string,ParticleID> PDTNameMap;
typedef PDTMap::const_iterator const_iterator;
typedef PDTNameMap::const_iterator const_iteratorByName;
diff -x Makefile -x '*.Po' -ur a/include/HepPDT/ProcessUnknownID.hh b/include/HepPDT/ProcessUnknownID.hh
--- a/include/HepPDT/ProcessUnknownID.hh 2007-09-04 14:39:16.000000000 -0400
+++ b/include/HepPDT/ProcessUnknownID.hh 2016-01-28 11:38:11.058292139 -0500
@@ -33,12 +33,12 @@
ParticleData * callProcessUnknownID( ParticleID, const ParticleDataTable & );
protected:
- ProcessUnknownID( ) : alreadyHere(false) {}
+ ProcessUnknownID( ) {}
virtual ~ProcessUnknownID( ) {}
private:
- bool alreadyHere;
+ static thread_local bool alreadyHere;
virtual ParticleData * processUnknownID( ParticleID,
const ParticleDataTable & ) = 0;
diff -x Makefile -x '*.Po' -ur a/src/HepPDT/ProcessUnknownID.cc b/src/HepPDT/ProcessUnknownID.cc
--- a/src/HepPDT/ProcessUnknownID.cc 2007-08-28 13:39:43.000000000 -0400
+++ b/src/HepPDT/ProcessUnknownID.cc 2016-01-28 11:45:18.165788033 -0500
@@ -9,14 +9,23 @@
namespace HepPDT {
+thread_local bool ProcessUnknownID::alreadyHere = false;
+
+class sentry {
+public:
+ sentry(bool& b) : b_(b) { b_ = true; }
+ ~sentry() { b_ = false; }
+private:
+ bool& b_;
+};
+
ParticleData * ProcessUnknownID::callProcessUnknownID
( ParticleID key, const ParticleDataTable & pdt )
{
ParticleData * pd = 0;
if( !alreadyHere ) {
- alreadyHere = true;
+ sentry s(alreadyHere);
pd = processUnknownID( key, pdt );
- alreadyHere = false;
}
return pd;
}