ATLAS Offline Software
Loading...
Searching...
No Matches
InternalOnline.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
10
11using namespace EventContainers;
13
14
16 m_mask(cache->fullSize()), m_waitNeeded(false) {}
17
18const std::vector < I_InternalIDC::hashPair >& InternalOnline::getAllHashPtrPair() const{
19 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
20 return m_map;
21}
22
23
26 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
27 return m_map.cend();
28}
29
32 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
33 return m_map.cbegin();
34}
35
37 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
38 auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
39 if(itr!= m_map.end() && itr->first==hashId) return itr;
40 return m_map.end();
41}
42
44 //lockguard to protect m_waitlist from multiple wait calls
45 std::scoped_lock lock (m_waitMutex);
46 if(m_waitNeeded.load(std::memory_order_acquire) == false) return;
47 using namespace EventContainers;
48 const void* ABORTstate = std::bit_cast<const void*>(IdentifiableCacheBase::ABORTEDflag);
49 while(!m_waitlist.empty()) {
50 IdentifierHash hash = m_waitlist.back();
52 const void* ptr = cacheLink->waitFor(hash);
53 if(ptr == ABORTstate) {
54 m_mask.unset(hash);
55 }
56 m_waitlist.pop_back();
57 }
58 m_map.clear();
59 m_mask.forEachSetBit([this](size_t index) {
60 const void* ptr = m_cacheLink->m_vec[index].load(std::memory_order_relaxed);//acquire sync is done by m_waitNeeded
61 m_map.emplace_back(index, ptr);
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.set(hashId);
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.set(hashId);
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.clear();
111 m_map.clear();
112 m_waitNeeded.store(true, std::memory_order_relaxed);
113}
114
116 if (!m_cacheLink->IMakerPresent()) [[unlikely]] return StatusCode::FAILURE;
117 auto ptr = m_cacheLink->get(hashId);
118 if(ptr) { m_mask.set(hashId); 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 (!m_cacheLink->IMakerPresent()) [[unlikely]] 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.set(hashId); //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.test(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 (!added.first) [[unlikely]] {
148 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
149 }
150 m_mask.set(hashId); //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}
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
#define unlikely(x)