Skip to content

Commit

Permalink
Merge pull request #4198 from wmtan/AvoidThreadLocals
Browse files Browse the repository at this point in the history
Avoid thread locals.
  • Loading branch information
ktf committed Jun 11, 2014
2 parents 5d5349b + baec0ff commit ebc64aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions FWCore/Utilities/BuildFile.xml
Expand Up @@ -4,6 +4,7 @@
<use name="rootcintex"/>
<use name="rootcore"/>
<use name="rootrflx"/>
<use name="tbb"/>
<use name="libuuid"/>
<export>
<lib name="1"/>
Expand Down
6 changes: 3 additions & 3 deletions FWCore/Utilities/src/FriendlyName.cc
Expand Up @@ -8,7 +8,7 @@
#include <string>
#include <boost/regex.hpp>
#include <iostream>
#include <map>
#include "tbb/concurrent_unordered_map.h"

//NOTE: This should probably be rewritten so that we break the class name into a tree where the template arguments are the node. On the way down the tree
// we look for '<' or ',' and on the way up (caused by finding a '>') we can apply the transformation to the output string based on the class name for the
Expand Down Expand Up @@ -133,8 +133,8 @@ namespace edm {
return result;
}
std::string friendlyName(std::string const& iFullName) {
typedef std::map<std::string, std::string> Map;
static thread_local Map s_fillToFriendlyName;
typedef tbb::concurrent_unordered_map<std::string, std::string> Map;
static Map s_fillToFriendlyName;
auto itFound = s_fillToFriendlyName.find(iFullName);
if(s_fillToFriendlyName.end()==itFound) {
itFound = s_fillToFriendlyName.insert(Map::value_type(iFullName, handleNamespaces(subFriendlyName(standardRenames(iFullName))))).first;
Expand Down
13 changes: 10 additions & 3 deletions FWCore/Utilities/src/TypeID.cc
Expand Up @@ -2,8 +2,8 @@
----------------------------------------------------------------------*/
#include <cassert>
#include <map>
#include <ostream>
#include "tbb/concurrent_unordered_map.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/FriendlyName.h"
#include "FWCore/Utilities/interface/Exception.h"
Expand Down Expand Up @@ -34,11 +34,18 @@ namespace {
}
}
}
struct TypeIDHasher {
size_t operator()(TypeID const& tid) const {
tbb::tbb_hash<std::string> hasher;
return hasher(std::string(tid.name()));
}
};


std::string const&
TypeID::className() const {
typedef std::map<edm::TypeID, std::string> Map;
static thread_local Map s_typeToName;
typedef tbb::concurrent_unordered_map<edm::TypeID, std::string, TypeIDHasher> Map;
static Map s_typeToName;

auto itFound = s_typeToName.find(*this);
if(s_typeToName.end() == itFound) {
Expand Down

0 comments on commit ebc64aa

Please sign in to comment.