Clarify buffer reclamation condition

This commit is contained in:
2024-05-04 18:17:44 -07:00
parent 08583f2ac0
commit 5a8275ffc1

View File

@@ -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);