diff --git a/flow/WriteOnlySet.actor.cpp b/flow/WriteOnlySet.actor.cpp index c79f8f4db7..8e2e0ecfd8 100644 --- a/flow/WriteOnlySet.actor.cpp +++ b/flow/WriteOnlySet.actor.cpp @@ -70,16 +70,16 @@ bool WriteOnlySet::erase(Index idx) { template bool WriteOnlySet::replace(Index idx, const Reference& lineage) { auto lineagePtr = reinterpret_cast(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(ptr ^ LOCK))); return false; } else { if (_set[idx].compare_exchange_strong(ptr, lineagePtr)) {