fix refcounting in WriteOnlySet

This commit is contained in:
Markus Pilman 2021-04-29 11:34:42 -06:00
parent 539a419f29
commit 7ab6fedb5b
1 changed files with 4 additions and 4 deletions

View File

@ -70,16 +70,16 @@ bool WriteOnlySet<T, IndexType, CAPACITY>::erase(Index idx) {
template <class T, class IndexType, IndexType CAPACITY>
bool WriteOnlySet<T, IndexType, CAPACITY>::replace(Index idx, const Reference<T>& lineage) {
auto lineagePtr = reinterpret_cast<uintptr_t>(lineage.getPtr());
if (lineage.isValid()) {
lineage->addref();
}
ASSERT((lineagePtr % 2) == 0); // this needs to be at least 2-byte aligned
while (true) {
if (lineage.isValid()) {
lineage->addref();
}
auto ptr = _set[idx].load();
if (ptr & LOCK) {
_set[idx].store(lineagePtr);
ASSERT(freeList.push(reinterpret_cast<T*>(ptr ^ LOCK)));
return false;
} else {
if (_set[idx].compare_exchange_strong(ptr, lineagePtr)) {