diff --git a/RootSet.cpp b/RootSet.cpp index 79b2996..f85ddcc 100644 --- a/RootSet.cpp +++ b/RootSet.cpp @@ -105,12 +105,15 @@ struct RootSet::Impl { void setOldestVersion(int64_t oldestVersion) { this->oldestVersion = oldestVersion; - // This condition is basically "while it would be incorrect to read - // firstToFree at oldestVersion - 1" + // The next buffer has an entry greater than all entries in this buffer. + // If the next buffer does not have an entry > `oldestVersion`, then this + // buffer is missing an entry <= oldestVersion on the right, so it's + // incorrect to read this buffer at `oldestVersion` and we can safely free + // it. while (firstToFree != nullptr && firstToFree->next != nullptr && firstToFree->next->versions()[firstToFree->next->end.load( std::memory_order_relaxed) - - 1] < oldestVersion) { + 1] <= oldestVersion) { auto *tmp = firstToFree; firstToFree = firstToFree->next; free(tmp);