ATLAS Offline Software
Loading...
Searching...
No Matches
EventContainers::InternalOnline Class Referencefinal

#include <InternalOnline.h>

Inheritance diagram for EventContainers::InternalOnline:
Collaboration diagram for EventContainers::InternalOnline:

Public Types

typedef EventContainers::hashPair< void > hashPair
typedef std::vector< hashPair >::const_iterator InternalConstItr
typedef void deleter_f(const void *p)

Public Member Functions

 InternalOnline (EventContainers::IdentifiableCacheBase *cache)
virtual InternalConstItr cbegin () const override
virtual InternalConstItr cend () const override
virtual InternalConstItr indexFind (IdentifierHash hashId) const override
virtual const std::vector< hashPair > & getAllHashPtrPair () const override
virtual ~InternalOnline ()=default
virtual void wait () const override
virtual bool tryAddFromCache (IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
virtual bool tryAddFromCache (IdentifierHash hashId) override
virtual std::vector< IdentifierHashgetAllCurrentHashes () const override
virtual size_t numberOfCollections () const override
void resetMask ()
virtual size_t fullSize () const noexcept override
virtual StatusCode fetchOrCreate (IdentifierHash hashId) override
virtual StatusCode fetchOrCreate (const std::vector< IdentifierHash > &hashIds) override
virtual bool insert (IdentifierHash hashId, const void *ptr) override
virtual const void * findIndexPtr (IdentifierHash hashId) const noexcept override
virtual StatusCode addLock (IdentifierHash hashId, const void *ptr) override
virtual void * removeCollection (IdentifierHash hashId) override
virtual void destructor (deleter_f *) noexcept override
virtual void cleanUp (deleter_f *) noexcept override

Private Attributes

EventContainers::IdentifiableCacheBasem_cacheLink
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
std::mutex m_waitMutex ATLAS_THREAD_SAFE
std::vector< bool > m_mask ATLAS_THREAD_SAFE
std::atomic< bool > m_waitNeeded ATLAS_THREAD_SAFE

Detailed Description

Definition at line 26 of file InternalOnline.h.

Member Typedef Documentation

◆ deleter_f

typedef void EventContainers::I_InternalIDC::deleter_f(const void *p)
inherited

Definition at line 14 of file I_InternalIDC.h.

◆ hashPair

Definition at line 37 of file I_InternalIDC.h.

◆ InternalConstItr

Definition at line 38 of file I_InternalIDC.h.

Constructor & Destructor Documentation

◆ InternalOnline()

InternalOnline::InternalOnline ( EventContainers::IdentifiableCacheBase * cache)

Definition at line 16 of file InternalOnline.cxx.

16 : m_cacheLink(cache),
17 m_mask(cache->fullSize(), false), m_waitNeeded(false) {}
EventContainers::IdentifiableCacheBase * m_cacheLink

◆ ~InternalOnline()

virtual EventContainers::InternalOnline::~InternalOnline ( )
virtualdefault

Member Function Documentation

◆ addLock()

StatusCode InternalOnline::addLock ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 145 of file InternalOnline.cxx.

145 {
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}
#define ATH_UNLIKELY(x)

◆ cbegin()

InternalConstItr InternalOnline::cbegin ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 32 of file InternalOnline.cxx.

32 {
33 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
34 return m_map.cbegin();
35}
virtual void wait() const override

◆ cend()

InternalConstItr InternalOnline::cend ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 26 of file InternalOnline.cxx.

26 {
27 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
28 return m_map.cend();
29}

◆ cleanUp()

void InternalOnline::cleanUp ( deleter_f * )
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 163 of file InternalOnline.cxx.

◆ destructor()

void InternalOnline::destructor ( deleter_f * )
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 159 of file InternalOnline.cxx.

159 {
160 //deliberately empty
161}

◆ fetchOrCreate() [1/2]

StatusCode InternalOnline::fetchOrCreate ( const std::vector< IdentifierHash > & hashIds)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 122 of file InternalOnline.cxx.

122 {
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}

◆ fetchOrCreate() [2/2]

StatusCode InternalOnline::fetchOrCreate ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 115 of file InternalOnline.cxx.

115 {
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}
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ findIndexPtr()

const void * InternalOnline::findIndexPtr ( IdentifierHash hashId) const
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 137 of file InternalOnline.cxx.

137 {
138 if(hashId < m_mask.size() and m_mask[hashId]) {
139 EventContainers::IdentifiableCacheBase* cacheLink ATLAS_THREAD_SAFE = m_cacheLink;
140 return cacheLink->findWait(hashId);
141 }
142 return nullptr;
143}
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE

◆ fullSize()

virtual size_t EventContainers::InternalOnline::fullSize ( ) const
inlineoverridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 40 of file InternalOnline.h.

40{ return m_mask.size(); }

◆ getAllCurrentHashes()

std::vector< IdentifierHash > InternalOnline::getAllCurrentHashes ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 93 of file InternalOnline.cxx.

93 {
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}
#define x

◆ getAllHashPtrPair()

const std::vector< I_InternalIDC::hashPair > & InternalOnline::getAllHashPtrPair ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 19 of file InternalOnline.cxx.

19 {
20 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
21 return m_map;
22}

◆ indexFind()

InternalConstItr InternalOnline::indexFind ( IdentifierHash hashId) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 37 of file InternalOnline.cxx.

37 {
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}
EventContainers::hashPair< void > hashPair
value_type value() const
unsigned int value_type

◆ insert()

bool InternalOnline::insert ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 130 of file InternalOnline.cxx.

130 {
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}

◆ numberOfCollections()

size_t InternalOnline::numberOfCollections ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 103 of file InternalOnline.cxx.

103 {
104 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
105 return m_map.size();
106}

◆ removeCollection()

void * InternalOnline::removeCollection ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 155 of file InternalOnline.cxx.

155 {
156 throw std::runtime_error("Do not remove things from an online IDC");
157}

◆ resetMask()

void InternalOnline::resetMask ( )

Definition at line 108 of file InternalOnline.cxx.

108 {
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}

◆ tryAddFromCache() [1/2]

bool InternalOnline::tryAddFromCache ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 82 of file InternalOnline.cxx.

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}

◆ tryAddFromCache() [2/2]

bool InternalOnline::tryAddFromCache ( IdentifierHash hashId,
EventContainers::IDC_WriteHandleBase & lock )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 68 of file InternalOnline.cxx.

68 {
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}
bool flag
Definition master.py:29

◆ wait()

void InternalOnline::wait ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 44 of file InternalOnline.cxx.

44 {
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();
52 EventContainers::IdentifiableCacheBase* cacheLink ATLAS_THREAD_SAFE = m_cacheLink;
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}

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/5]

std::vector< IdentifierHash > m_waitlist EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 51 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [2/5]

std::vector<I_InternalIDC::hashPair> m_map EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 52 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [3/5]

std::mutex m_waitMutex EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 53 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [4/5]

std::vector<bool> m_mask EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 54 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [5/5]

std::atomic<bool> m_waitNeeded EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 55 of file InternalOnline.h.

◆ m_cacheLink

EventContainers::IdentifiableCacheBase* EventContainers::InternalOnline::m_cacheLink
private

Definition at line 50 of file InternalOnline.h.


The documentation for this class was generated from the following files: