40 const void *ptr1 =
nullptr;
42 if(
m_vec[hash].compare_exchange_strong(ptr1,
INVALID, std::memory_order_relaxed, std::memory_order_relaxed)){
51 wait.emplace_back(hash);
61 size_t s =
m_vec.size();
63 for (
size_t i=0; i<s ;i++) {
64 const void* ptr =
m_vec[i].load(std::memory_order_relaxed);
65 m_vec[i].store(
nullptr, std::memory_order_relaxed);
72 for (
size_t i=0; i<s ;i++)
m_vec[i].store(
nullptr, std::memory_order_relaxed);
81 size_t s =
m_vec.size();
82 for (
size_t i=0; i<s ;i++) {
83 const void* p =
m_vec[i].load(std::memory_order_relaxed);
84 if(p && p <
ABORTED) deleter (p);
90 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
96 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
104 const void* p =
m_vec[hash].load(std::memory_order_acquire);
112 std::atomic<const void*> &myatomic =
m_vec[hash];
113 const void* item = myatomic.load(std::memory_order_acquire);
116 myatomic.wait(item, std::memory_order_relaxed);
117 item = myatomic.load(std::memory_order_acquire);
132 m_vec[hash].notify_all();
138 const void* ptr =
nullptr;
141 if(
m_vec[hash].compare_exchange_strong(ptr,
INVALID) ) {
151 ptr =
m_maker->typelessMake (hash).release();
160 m_vec[hash].store( ptr );
170 if(ptr ==
ABORTED)
return nullptr;
178 const void* ptr =
get(hash);
179 if(ptr !=
nullptr) mask[hash] =
true;
191 std::vector<IdentifierHash> ret;
193 size_t s =
m_vec.size();
194 for (
size_t i =0; i<s; i++) {
195 const void* p =
m_vec[i].load(std::memory_order_relaxed);
205 if (hash >=
m_vec.size()) [[
unlikely]]
return std::make_pair(
false,
nullptr);
206 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
207 const void* nul=
nullptr;
208 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_relaxed)){
210 return std::make_pair(
true, p);
213 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_acquire)){
216 return std::make_pair(
true, p);
218 return std::make_pair(
false, invalid);
225 assert(hash <
m_vec.size());
226 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
228 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_relaxed)){
231 return std::make_pair(
true, p);
233 const void* nul=
nullptr;
234 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_acquire)){
236 return std::make_pair(
true, p);
238 return std::make_pair(
false, nul);
244 std::pair<bool, const void*> b =
addLock(hash, p.get());
245 if(b.first) p.release();
253 std::pair<bool, const void*> b =
add(hash, p.get());
254 if(b.first) p.release();
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
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.
void notifyHash(IdentifierHash hash)
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.
void deleter_f(const void *p)
void cleanUp(deleter_f *deleter)
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),...
static constexpr uintptr_t ABORTEDflag
void clear(deleter_f *deleter)
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
std::unique_lock< mutex_t > uniqueLock
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.
static constexpr uintptr_t INVALIDflag
This is a "hash" representation of an Identifier.
bool add(const std::string &hname, TKey *tobj)
const void *const INVALID
const void *const ABORTED