ATLAS Offline Software
Loading...
Searching...
No Matches
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-2025 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
8#define EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
9
10
12#include <memory>
13#include <mutex>
14#include <atomic>
17
18namespace EventContainers {
19
20
21
24
25public:
26//here for access from other classes
27static constexpr uintptr_t INVALIDflag = UINTPTR_MAX;
28static constexpr uintptr_t ABORTEDflag = UINTPTR_MAX-1;
29
30
31typedef std::true_type thread_safe;
34
35 struct IMaker
36 {
37 bool m_IsReEntrant = false;
38 virtual ~IMaker() {}
39 virtual void_unique_ptr typelessMake (IdentifierHash hash) const = 0; // unique_ptr<T>??
40 };
41
43 const void* find (IdentifierHash hash) noexcept;
45 const void* findWait (IdentifierHash hash);
46
48 const void* get (IdentifierHash hash);
49
51 std::vector<IdentifierHash> ids();
52
53 std::pair<bool, const void*> add (IdentifierHash hash, const void* p) noexcept;
54
55 // addLock is same as method above except we check for invalid state first,
56 // more optimal for calling using writehandle lock method
57 std::pair<bool, const void*> addLock (IdentifierHash hash, const void* p) noexcept;
58 std::pair<bool, const void*> addLock (IdentifierHash hash, void_unique_ptr p) noexcept;
59 std::pair<bool, const void*> add (IdentifierHash hash, void_unique_ptr p) noexcept;
60
61 bool IMakerPresent() const { return m_maker!=nullptr; }
62
67 int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector<IdentifierHash>&);
68
71
74
76 const void* waitFor(IdentifierHash);
77
79 void createSet (const std::vector<IdentifierHash>& hashes, std::vector<bool> &mask);
80
81 size_t fullSize() const { return m_vec.size(); }
83 size_t numberOfHashes();
84
85protected:
86 IdentifiableCacheBase (IdentifierHash maxHash, const IMaker* maker);
88 void clear (deleter_f* deleter);
89 void cleanUp(deleter_f* deleter);//Call once before destruction
90 void notifyHash(IdentifierHash hash);
91private:
92 std::vector<std::atomic<const void*> > m_vec;
93 friend class InternalOnline;
95
96 typedef std::mutex mutex_t;
97 typedef std::scoped_lock<mutex_t> lock_t;
98 typedef std::unique_lock<mutex_t> uniqueLock;
101 std::atomic<size_t> m_currentHashes;
102};
103
104
105} // namespace EventContainers
106
107
108#endif // not EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
std::vector< std::atomic< const void * > > m_vec
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...
const void * waitFor(IdentifierHash)
Halts the thread until the require hash is completed or aborted.
size_t numberOfHashes()
In a concurrent situation this number isn't necessarily perfectly synchronised with ids()....
int itemAborted(IdentifierHash)
Returns 1 is the item has been aborted otherwise 0.
int itemInProgress(IdentifierHash)
Returns 1 is the item is inprogress otherwise 0.
std::vector< IdentifierHash > ids()
In a threaded situation this collection will be valid but will not container hashes later added.
const void * get(IdentifierHash hash)
Try to make payload if not there.
std::pair< bool, const void * > addLock(IdentifierHash hash, const void *p) noexcept
int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector< IdentifierHash > &)
Checks if the item is completed if it is not started it extablishes lock (returns 0),...
void createSet(const std::vector< IdentifierHash > &hashes, std::vector< bool > &mask)
Create a set of hashes, updates an IDC mask as appropriate.
IdentifiableCacheBase(IdentifierHash maxHash, const IMaker *maker)
std::pair< bool, const void * > add(IdentifierHash hash, const void *p) noexcept
const void * findWait(IdentifierHash hash)
Retrieve ptr, will wait if there is something in progress.
const void * find(IdentifierHash hash) noexcept
Return payload if there, null if not there.
This is a "hash" representation of an Identifier.
virtual void_unique_ptr typelessMake(IdentifierHash hash) const =0