ATLAS Offline Software
IdentifiableCacheBase.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id: IdentifiableCacheBase.h 791541 2017-01-09 10:43:53Z smh $
8 
9 
10 
11 #ifndef EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
12 #define EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
13 
14 
16 #include <mutex>
17 #include <atomic>
19 
20 
21 namespace EventContainers {
22 
23 
24 
26 {
27 
28 public:
29 //here for access from other classes
30 static constexpr uintptr_t INVALIDflag = UINTPTR_MAX;
31 static constexpr uintptr_t ABORTEDflag = UINTPTR_MAX-1;
32 
33 
34 typedef std::true_type thread_safe;
35 
37 
38  struct IMaker
39  {
40  bool m_IsReEntrant = false;
41  virtual ~IMaker() {}
42  virtual void_unique_ptr typelessMake (IdentifierHash hash) const = 0; // unique_ptr<T>??
43  };
44 
46  const void* find (IdentifierHash hash) noexcept;
48  const void* findWait (IdentifierHash hash);
49 
51  const void* get (IdentifierHash hash);
52 
54  std::vector<IdentifierHash> ids();
55 
56  std::pair<bool, const void*> add (IdentifierHash hash, const void* p) noexcept;
57 
58  // addLock is same as method above except we check for invalid state first,
59  // more optimal for calling using writehandle lock method
60  std::pair<bool, const void*> addLock (IdentifierHash hash, const void* p) noexcept;
61  std::pair<bool, const void*> addLock (IdentifierHash hash, void_unique_ptr p) noexcept;
62  std::pair<bool, const void*> add (IdentifierHash hash, void_unique_ptr p) noexcept;
63 
64  bool IMakerPresent() const { return m_maker!=nullptr; }
65 
70  int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector<IdentifierHash>&);
71 
74 
77 
79  const void* waitFor(IdentifierHash);
80 
82  void createSet (const std::vector<IdentifierHash>& hashes, std::vector<bool> &mask);
83 
84  size_t fullSize() const { return m_vec.size(); }
86  size_t numberOfHashes();
87 
88 protected:
89  IdentifiableCacheBase (IdentifierHash maxHash, const IMaker* maker);
91  void clear (deleter_f* deleter);
92  void cleanUp(deleter_f* deleter);//Call once before destruction
94 private:
95  std::vector<std::atomic<const void*> > m_vec;
96  friend class InternalOnline;
97  const IMaker* m_maker;
98 
100  typedef std::scoped_lock<mutex_t> lock_t;
101  typedef std::unique_lock<mutex_t> uniqueLock;
104  std::atomic<size_t> m_currentHashes;
105 };
106 
107 
108 } // namespace EventContainers
109 
110 
111 #endif // not EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
EventContainers::IdentifiableCacheBase::findWait
const void * findWait(IdentifierHash hash)
Retrieve ptr, will wait if there is something in progress.
Definition: IdentifiableCacheBase.cxx:123
EventContainers::InternalOnline
Definition: InternalOnline.h:26
EventContainers::IdentifiableCacheBase
Definition: IdentifiableCacheBase.h:26
EventContainers::IdentifiableCacheBase::get
const void * get(IdentifierHash hash)
Try to make payload if not there.
Definition: IdentifiableCacheBase.cxx:136
EventContainers::IdentifiableCacheBase::ABORTEDflag
static constexpr uintptr_t ABORTEDflag
Definition: IdentifiableCacheBase.h:31
EventContainers::IdentifiableCacheBase::IMaker::m_IsReEntrant
bool m_IsReEntrant
Definition: IdentifiableCacheBase.h:40
EventContainers::IdentifiableCacheBase::numberOfHashes
size_t numberOfHashes()
In a concurrent situation this number isn't necessarily perfectly synchronised with ids()....
Definition: IdentifiableCacheBase.cxx:185
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
EventContainers::IdentifiableCacheBase::m_mutex
mutex_t m_mutex
Definition: IdentifiableCacheBase.h:102
EventContainers::IdentifiableCacheBase::mutex_t
std::mutex mutex_t
Definition: IdentifiableCacheBase.h:99
EventContainers::IdentifiableCacheBase::m_maker
const IMaker * m_maker
Definition: IdentifiableCacheBase.h:97
EventContainers::IdentifiableCacheBase::lock_t
std::scoped_lock< mutex_t > lock_t
Definition: IdentifiableCacheBase.h:100
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
EventContainers::IdentifiableCacheBase::~IdentifiableCacheBase
~IdentifiableCacheBase()
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
EventContainers::IdentifiableCacheBase::thread_safe
std::true_type thread_safe
Definition: IdentifiableCacheBase.h:34
deleter_f
void deleter_f(const void *p)
Definition: deleter.h:12
IDC_WriteHandleBase.h
EventContainers::IdentifiableCacheBase::IdentifiableCacheBase
IdentifiableCacheBase(IdentifierHash maxHash, const IMaker *maker)
Definition: IdentifiableCacheBase.cxx:28
EventContainers::IdentifiableCacheBase::tryLock
int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector< IdentifierHash > &)
Checks if the item is completed if it is not started it extablishes lock (returns 0),...
Definition: IdentifiableCacheBase.cxx:39
EventContainers::IdentifiableCacheBase::fullSize
size_t fullSize() const
Definition: IdentifiableCacheBase.h:84
EventContainers::IdentifiableCacheBase::uniqueLock
std::unique_lock< mutex_t > uniqueLock
Definition: IdentifiableCacheBase.h:101
EventContainers::IdentifiableCacheBase::IMakerPresent
bool IMakerPresent() const
Definition: IdentifiableCacheBase.h:64
EventContainers::IdentifiableCacheBase::clear
void clear(deleter_f *deleter)
Definition: IdentifiableCacheBase.cxx:59
EventContainers::IdentifiableCacheBase::itemAborted
int itemAborted(IdentifierHash)
Returns 1 is the item has been aborted otherwise 0.
Definition: IdentifiableCacheBase.cxx:90
IdentifierHash.h
EventContainers::IdentifiableCacheBase::notifyHash
void notifyHash(IdentifierHash hash)
Definition: IdentifiableCacheBase.cxx:131
EventContainers::IdentifiableCacheBase::m_currentHashes
std::atomic< size_t > m_currentHashes
Holds the number of valid hashes in container, in concurrent use it is not guaranteed to be up to dat...
Definition: IdentifiableCacheBase.h:104
EventContainers::IdentifiableCacheBase::m_vec
std::vector< std::atomic< const void * > > m_vec
Definition: IdentifiableCacheBase.h:95
EventContainers::IdentifiableCacheBase::createSet
void createSet(const std::vector< IdentifierHash > &hashes, std::vector< bool > &mask)
Create a set of hashes, updates an IDC mask as appropriate.
Definition: IdentifiableCacheBase.cxx:176
void_unique_ptr
Definition: deleter.h:16
EventContainers::IdentifiableCacheBase::IMaker::typelessMake
virtual void_unique_ptr typelessMake(IdentifierHash hash) const =0
EventContainers::IdentifiableCacheBase::itemInProgress
int itemInProgress(IdentifierHash)
Returns 1 is the item is inprogress otherwise 0.
Definition: IdentifiableCacheBase.cxx:96
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
EventContainers::IdentifiableCacheBase::find
const void * find(IdentifierHash hash) noexcept
Return payload if there, null if not there.
Definition: IdentifiableCacheBase.cxx:102
EventContainers::IdentifiableCacheBase::waitFor
const void * waitFor(IdentifierHash)
Halts the thread until the require hash is completed or aborted.
Definition: IdentifiableCacheBase.cxx:111
EventContainers::IdentifiableCacheBase::add
std::pair< bool, const void * > add(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:204
EventContainers::IdentifiableCacheBase::ids
std::vector< IdentifierHash > ids()
In a threaded situation this collection will be valid but will not container hashes later added.
Definition: IdentifiableCacheBase.cxx:190
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:13
EventContainers::IdentifiableCacheBase::IMaker
Definition: IdentifiableCacheBase.h:39
deleter.h
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
EventContainers::IdentifiableCacheBase::IMaker::~IMaker
virtual ~IMaker()
Definition: IdentifiableCacheBase.h:41
EventContainers::IdentifiableCacheBase::INVALIDflag
static constexpr uintptr_t INVALIDflag
Definition: IdentifiableCacheBase.h:30
EventContainers::IdentifiableCacheBase::addLock
std::pair< bool, const void * > addLock(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:223
EventContainers::IdentifiableCacheBase::cleanUp
void cleanUp(deleter_f *deleter)
Definition: IdentifiableCacheBase.cxx:78