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(), false), 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[hash] = false;
56 }
57 m_waitlist.pop_back();
58 }
59 m_map.clear();
60 for(size_t i =0;i<m_mask.size();i++){
61 if(m_mask[i]) m_map.emplace_back(i, m_cacheLink->m_vec[i].load(std::memory_order_relaxed));//acquire sync is done by m_waitNeeded
62 }
63 //Full sync to release m_map and acquire pointers retrieved
64 //Probably done by the lock descoping but this is easier to read.
65 m_waitNeeded.store(false, std::memory_order_seq_cst);
66}
67
69 int flag = m_cacheLink->tryLock(hashId, lock, m_waitlist);
70 //Relaxed since this should not be running in threaded situation.
71 if(!m_waitlist.empty()) m_waitNeeded.store(true, std::memory_order_relaxed);
72 if(flag > 0) {
73 if(flag!=3){
74 m_mask[hashId] = true;
75 m_waitNeeded.store(true, std::memory_order_relaxed);
76 }
77 return true;
78 }
79 return false;
80}
81
83{
84 auto ptr = m_cacheLink->find(hashId);
85 if(ptr==nullptr) {
86 return false;
87 }
88 m_mask[hashId] = true;
89 m_waitNeeded.store(true, std::memory_order_relaxed);
90 return true;
91}
92
93std::vector<IdentifierHash> InternalOnline::getAllCurrentHashes() const {
94 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
95 std::vector<IdentifierHash> ids;
96 ids.reserve(m_map.size());
97 for(auto &x : m_map) {
98 ids.emplace_back(x.first);
99 }
100 return ids;
101}
102
104 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
105 return m_map.size();
106}
107
109 if(m_waitNeeded.load(std::memory_order_relaxed)) wait();
110 m_mask.assign(m_cacheLink->fullSize(), false);
111 m_map.clear();
112 m_waitNeeded.store(true, std::memory_order_relaxed);
113}
114
116 if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
117 auto ptr = m_cacheLink->get(hashId);
118 if(ptr) { m_mask[hashId] =true; m_waitNeeded.store(true, std::memory_order_relaxed); }
119 return StatusCode::SUCCESS;
120}
121
122StatusCode InternalOnline::fetchOrCreate(const std::vector<IdentifierHash> &/*hashIds*/) {
123 throw std::runtime_error("Not implemented");
124// if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
125// m_cacheLink->createSet(hashIds, m_mask);
126// return StatusCode::SUCCESS;
127}
128
129
130bool InternalOnline::insert(IdentifierHash hashId, const void* ptr) {
131 std::pair<bool, const void*> cacheinserted = m_cacheLink->add(hashId, ptr);
132 m_mask[hashId] = true; //it wasn't added it is already present therefore mask could be true
133 m_waitNeeded.store(true, std::memory_order_relaxed);
134 return ptr == cacheinserted.second;
135}
136
137const void* InternalOnline::findIndexPtr(IdentifierHash hashId) const noexcept {
138 if(hashId < m_mask.size() and m_mask[hashId]) {
140 return cacheLink->findWait(hashId);
141 }
142 return nullptr;
143}
144
145StatusCode InternalOnline::addLock(IdentifierHash hashId, const void* ptr) {
146 std::pair<bool, const void*> added = m_cacheLink->addLock(hashId, ptr);
147 if(ATH_UNLIKELY(!added.first)) {
148 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
149 }
150 m_mask[hashId] = true; //it wasn't added it is already present therefore mask could be true
151 m_waitNeeded.store(true, std::memory_order_relaxed);
152 return StatusCode::SUCCESS;
153}
154
156 throw std::runtime_error("Do not remove things from an online IDC");
157}
158
160 //deliberately empty
161}
162
164 resetMask();
165}
#define ATH_UNLIKELY(x)
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.
value_type value() const
unsigned int value_type