Commit 1333361a authored by Berenger Bramas's avatar Berenger Bramas
Browse files

update lock free array to ensure to have true on activation

parent 1ce23567
Pipeline #101806 failed with stages
in 23 minutes and 10 seconds
......@@ -55,14 +55,23 @@ public:
k.reset(new Locker());
}
}
#ifndef NDEBUG
~lock_free_bool_array(){
for(auto& k : keys){
assert(k->lock.load() == Available);
assert(k->ownerId.load() == NoOwner);
}
}
#endif
void lock(const long int inKey){
Locker* k = keys[inKey%keys.size()].get();
if(k->ownerId.load() != omp_get_thread_num()){
int expected = Available;
while(!std::atomic_compare_exchange_strong(&k->lock, &expected, Busy)){
usleep(1);
expected = Available;
}
assert(k->ownerId.load() == NoOwner);
k->ownerId.store(omp_get_thread_num());
k->counter = 0; // must remain
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment