41 const void *ptr1 =
nullptr;
43 if(
m_vec[hash].compare_exchange_strong(ptr1,
INVALID, std::memory_order_relaxed, std::memory_order_relaxed)){
52 wait.emplace_back(hash);
62 size_t s =
m_vec.size();
64 for (
size_t i=0; i<s ;i++) {
65 const void* ptr =
m_vec[i].load(std::memory_order_relaxed);
66 m_vec[i].store(
nullptr, std::memory_order_relaxed);
73 for (
size_t i=0; i<s ;i++)
m_vec[i].store(
nullptr, std::memory_order_relaxed);
81 std::atomic_thread_fence(std::memory_order_acquire);
84 for (
size_t i=0; i<s ;i++) {
85 const void* p =
m_vec[i].load(std::memory_order_relaxed);
86 if(p && p <
ABORTED) deleter (p);
92 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
98 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
106 const void* p =
m_vec[hash].load(std::memory_order_acquire);
114 std::atomic<const void*> &myatomic =
m_vec[hash];
115 const void* item = myatomic.load(std::memory_order_acquire);
118 myatomic.wait(item, std::memory_order_relaxed);
119 item = myatomic.load(std::memory_order_acquire);
134 m_vec[hash].notify_all();
140 const void* ptr =
nullptr;
143 if(
m_vec[hash].compare_exchange_strong(ptr,
INVALID) ) {
150 if(!
m_maker->m_IsReEntrant) lock.lock();
153 ptr =
m_maker->typelessMake (hash).release();
162 m_vec[hash].store( ptr );
172 if(ptr ==
ABORTED)
return nullptr;
180 const void* ptr =
get(hash);
181 if(ptr !=
nullptr) mask[hash] =
true;
193 std::vector<IdentifierHash> ret;
195 size_t s =
m_vec.size();
196 for (
size_t i =0; i<s; i++) {
197 const void* p =
m_vec[i].load(std::memory_order_relaxed);
208 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
209 const void* nul=
nullptr;
210 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_relaxed)){
212 return std::make_pair(
true, p);
215 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_acquire)){
218 return std::make_pair(
true, p);
220 return std::make_pair(
false, invalid);
227 assert(hash <
m_vec.size());
228 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
230 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_relaxed)){
233 return std::make_pair(
true, p);
235 const void* nul=
nullptr;
236 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_acquire)){
238 return std::make_pair(
true, p);
240 return std::make_pair(
false, nul);
246 std::pair<bool, const void*> b =
addLock(hash, p.get());
247 if(b.first) p.release();
255 std::pair<bool, const void*> b =
add(hash, p.get());
256 if(b.first) p.release();
void LockOn(std::atomic< const void * > *in) noexcept
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