ATLAS Offline Software
Loading...
Searching...
No Matches
InternalOnline.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
11
12using namespace EventContainers;
14
15
17 m_mask(cache->fullSize()), m_waitNeeded(false) {}
18
19const std::vector < I_InternalIDC::hashPair >& InternalOnline::getAllHashPtrPair() const{
20 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
21 return m_map;
22}
23
24
27 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
28 return m_map.cend();
29}
30
33 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
34 return m_map.cbegin();
35}
36
38 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
39 auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
40 if(itr!= m_map.end() && itr->first==hashId) return itr;
41 return m_map.end();
42}
43
45 //lockguard to protect m_waitlist from multiple wait calls
46 std::scoped_lock lock (m_waitMutex);
47 if(m_waitNeeded.load(std::memory_order_acquire) == false) return;
48 using namespace EventContainers;
49 const void* ABORTstate = std::bit_cast<const void*>(IdentifiableCacheBase::ABORTEDflag);
50 while(!m_waitlist.empty()) {
51 IdentifierHash hash = m_waitlist.back();
53 const void* ptr = cacheLink->waitFor(hash);
54 if(ptr == ABORTstate) {
55 m_mask.unset(hash);
56 }
57 m_waitlist.pop_back();
58 }
59 m_map.clear();
60 m_mask.forEachSetBit([this](size_t index) {
61 const void* ptr = m_cacheLink->m_vec[index].load(std::memory_order_relaxed);//acquire sync is done by m_waitNeeded
62 m_map.emplace_back(index, ptr);
63 });
64 //Full sync to release m_map and acquire pointers retrieved
65 //Probably done by the lock descoping but this is easier to read.
66 m_waitNeeded.store(false, std::memory_order_seq_cst);
67}
68
70 int flag = m_cacheLink->tryLock(hashId, lock, m_waitlist);
71 //Relaxed since this should not be running in threaded situation.
72 if(!m_waitlist.empty()) m_waitNeeded.store(true, std::memory_order_relaxed);
73 if(flag > 0) {
74 if(flag!=3){
75 m_mask.set(hashId);
76 m_waitNeeded.store(true, std::memory_order_relaxed);
77 }
78 return true;
79 }
80 return false;
81}
82
84{
85 auto ptr = m_cacheLink->find(hashId);
86 if(ptr==nullptr) {
87 return false;
88 }
89 m_mask.set(hashId);
90 m_waitNeeded.store(true, std::memory_order_relaxed);
91 return true;
92}
93
94std::vector<IdentifierHash> InternalOnline::getAllCurrentHashes() const {
95 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
96 std::vector<IdentifierHash> ids;
97 ids.reserve(m_map.size());
98 for(auto &x : m_map) {
99 ids.emplace_back(x.first);
100 }
101 return ids;
102}
103
105 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
106 return m_map.size();
107}
108
110 if(m_waitNeeded.load(std::memory_order_relaxed)) wait();
111 m_mask.clear();
112 m_map.clear();
113 m_waitNeeded.store(true, std::memory_order_relaxed);
114}
115
117 if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
118 auto ptr = m_cacheLink->get(hashId);
119 if(ptr) { m_mask.set(hashId); m_waitNeeded.store(true, std::memory_order_relaxed); }
120 return StatusCode::SUCCESS;
121}
122
123StatusCode InternalOnline::fetchOrCreate(const std::vector<IdentifierHash> &/*hashIds*/) {
124 throw std::runtime_error("Not implemented");
125// if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
126// m_cacheLink->createSet(hashIds, m_mask);
127// return StatusCode::SUCCESS;
128}
129
130
131bool InternalOnline::insert(IdentifierHash hashId, const void* ptr) {
132 std::pair<bool, const void*> cacheinserted = m_cacheLink->add(hashId, ptr);
133 m_mask.set(hashId); //it wasn't added it is already present therefore mask could be true
134 m_waitNeeded.store(true, std::memory_order_relaxed);
135 return ptr == cacheinserted.second;
136}
137
138const void* InternalOnline::findIndexPtr(IdentifierHash hashId) const noexcept {
139 if(hashId < m_mask.size() and m_mask.test(hashId)) {
141 return cacheLink->findWait(hashId);
142 }
143 return nullptr;
144}
145
146StatusCode InternalOnline::addLock(IdentifierHash hashId, const void* ptr) {
147 std::pair<bool, const void*> added = m_cacheLink->addLock(hashId, ptr);
148 if(ATH_UNLIKELY(!added.first)) {
149 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
150 }
151 m_mask.set(hashId); //it wasn't added it is already present therefore mask could be true
152 m_waitNeeded.store(true, std::memory_order_relaxed);
153 return StatusCode::SUCCESS;
154}
155
157 throw std::runtime_error("Do not remove things from an online IDC");
158}
159
161 //deliberately empty
162}
163
165 resetMask();
166}
#define ATH_UNLIKELY(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
I_InternalIDC::InternalConstItr InternalConstItr
#define x
Define macros for attributes used to control the static checker.
std::vector< hashPair >::const_iterator InternalConstItr
EventContainers::hashPair< void > hashPair
void deleter_f(const void *p)
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
virtual bool insert(IdentifierHash hashId, const void *ptr) override
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
virtual void wait() const override
virtual void cleanUp(deleter_f *) noexcept override
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
virtual size_t fullSize() const noexcept override
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
virtual void destructor(deleter_f *) noexcept override
virtual void * removeCollection(IdentifierHash hashId) override
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
virtual InternalConstItr cbegin() const override
InternalOnline(EventContainers::IdentifiableCacheBase *cache)
virtual InternalConstItr cend() const override
virtual size_t numberOfCollections() const override
EventContainers::IdentifiableCacheBase * m_cacheLink
This is a "hash" representation of an Identifier.
constexpr value_type value() const
unsigned int value_type
Definition index.py:1