From 5a8275ffc145429a8c28814d31ec533fc27c3504 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Sat, 4 May 2024 18:17:44 -0700 Subject: [PATCH] Clarify buffer reclamation condition --- RootSet.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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);