feat: a cleared ring can resume its absolute count at a given origin
CI / debug (tests + all adapters) (push) Canceled after 0s
CI / coverage (floor + measured table) (push) Canceled after 0s
CI / asan (AddressSanitizer) (push) Canceled after 0s

A derived ring that is emptied and refilled from its source's retained
window has to come back numbered as the source is. `clear()` restarts it
at 0, which leaves every absolute index -- `base()`, `produced()`,
`copy_from()` -- short by that origin for a whole window's worth of data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martino FerrariandClaude Opus 4.6 committed 2026-10-15 16:30:05 +02:00
1 parent 9790becb33
commit 3ad02e5120
2 files changed
+49

No files matched your search

+12
View File
@@ -127,6 +127,18 @@ class RingBuffer {
/// pushing).
void clear() noexcept { produced_.store(0, std::memory_order_relaxed); }
/// Consumer thread only: discards every element and resumes the absolute count
/// at `absolute`, so the next push() lands there (not safe while a producer is
/// pushing).
///
/// This is for a *recompute*: a ring whose contents are derived from another is
/// emptied and refilled from a given absolute origin, and it must come back
/// numbered as its source is. clear() would restart it at 0 and leave every
/// absolute index -- base(), produced(), copy_from() -- off by that origin.
void clear_to(u64 absolute) noexcept {
produced_.store(absolute, std::memory_order_relaxed);
}
private:
u64 cap_;
u64 mask_;