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);
82 size_t s =
m_vec.size();
83 for (
size_t i=0; i<s ;i++) {
84 const void* p =
m_vec[i].load(std::memory_order_relaxed);
85 if(p && p <
ABORTED) deleter (p);
91 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
97 const void* p =
m_vec[hash].load(std::memory_order_relaxed);
105 const void* p =
m_vec[hash].load(std::memory_order_acquire);
113 std::atomic<const void*> &myatomic =
m_vec[hash];
114 const void* item = myatomic.load(std::memory_order_acquire);
117 myatomic.wait(item, std::memory_order_relaxed);
118 item = myatomic.load(std::memory_order_acquire);
133 m_vec[hash].notify_all();
139 const void* ptr =
nullptr;
142 if(
m_vec[hash].compare_exchange_strong(ptr,
INVALID) ) {
152 ptr =
m_maker->typelessMake (hash).release();
161 m_vec[hash].store( ptr );
171 if(ptr ==
ABORTED)
return nullptr;
179 const void* ptr =
get(hash);
180 if(ptr !=
nullptr) mask[hash] =
true;
192 std::vector<IdentifierHash> ret;
194 size_t s =
m_vec.size();
195 for (
size_t i =0; i<s; i++) {
196 const void* p =
m_vec[i].load(std::memory_order_relaxed);
207 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
208 const void* nul=
nullptr;
209 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_relaxed)){
211 return std::make_pair(
true, p);
214 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_acquire)){
217 return std::make_pair(
true, p);
219 return std::make_pair(
false, invalid);
226 assert(hash <
m_vec.size());
227 if(p==
nullptr)
return std::make_pair(
false,
nullptr);
229 if(
m_vec[hash].compare_exchange_strong(invalid, p, std::memory_order_release, std::memory_order_relaxed)){
232 return std::make_pair(
true, p);
234 const void* nul=
nullptr;
235 if(
m_vec[hash].compare_exchange_strong(nul, p, std::memory_order_release, std::memory_order_acquire)){
237 return std::make_pair(
true, p);
239 return std::make_pair(
false, nul);
245 std::pair<bool, const void*> b =
addLock(hash, p.get());
246 if(b.first) p.release();
254 std::pair<bool, const void*> b =
add(hash, p.get());
255 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