CMS 3D CMS Logo

Proxy.cc
Go to the documentation of this file.
1 #include <map>
2 #include <mutex>
3 
5 
6 using namespace ThePEG;
7 
9 
10 typedef std::map<ProxyBase::ProxyID, std::weak_ptr<ProxyBase> > ProxyMap;
11 
13  static struct Sentinel {
14  Sentinel() : instance(new ProxyMap) {}
15  ~Sentinel() {
16  delete instance;
17  instance = nullptr;
18  }
19 
21  } sentinel;
22 
23  return sentinel.instance;
24 }
25 
27 
29  std::scoped_lock scoped_lock(mutex);
30 
32  if (map)
33  map->erase(id);
34 }
35 
36 std::shared_ptr<ProxyBase> ProxyBase::create(ctor_t ctor) {
37  static ProxyBase::ProxyID nextProxyID = 0;
38 
39  std::scoped_lock scoped_lock(mutex);
40 
41  std::shared_ptr<ProxyBase> proxy(ctor(++nextProxyID));
42 
44  if (map)
45  map->insert(ProxyMap::value_type(proxy->getID(), proxy));
46 
47  return proxy;
48 }
49 
50 std::shared_ptr<ProxyBase> ProxyBase::find(ProxyID id) {
51  std::scoped_lock scoped_lock(mutex);
52 
54  if (!map)
55  return std::shared_ptr<ProxyBase>();
56 
57  ProxyMap::const_iterator pos = map->find(id);
58  if (pos == map->end())
59  return std::shared_ptr<ProxyBase>();
60 
61  return std::shared_ptr<ProxyBase>(pos->second);
62 }
pos
Definition: PixelAliasList.h:18
ThePEG::ProxyBase::ProxyBase
ProxyBase(ProxyID id)
Definition: Proxy.cc:26
ThePEG
Definition: Herwig7Interface.h:24
ThePEG::ProxyBase::find
static std::shared_ptr< ProxyBase > find(ProxyID id)
Definition: Proxy.cc:50
ThePEG::ProxyBase::ProxyID
unsigned long ProxyID
Definition: Proxy.h:16
Proxy.h
mutex
static std::mutex mutex
Definition: Proxy.cc:8
getProxyMapInstance
static ProxyMap * getProxyMapInstance()
Definition: Proxy.cc:12
ThePEG::ProxyBase::~ProxyBase
virtual ~ProxyBase()
Definition: Proxy.cc:28
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
ProxyMap
std::map< ProxyBase::ProxyID, std::weak_ptr< ProxyBase > > ProxyMap
Definition: Proxy.cc:10
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
ThePEG::ProxyBase::create
static std::shared_ptr< ProxyBase > create(ctor_t ctor)
Definition: Proxy.cc:36
genParticles_cff.map
map
Definition: genParticles_cff.py:11