Commit 89383c3a authored by Chad Austin's avatar Chad Austin Committed by Facebook GitHub Bot

remove unused LockFreeRingBuffer functionality

Summary:
Nothing uses the skipFraction in LockFreeRingBuffer::currentTail, and
floating point math for discrete fractions can be hard to reason
about, so remove this dead code.

Differential Revision: D27717906

fbshipit-source-id: b25e2bea25ab66c59e8c76a80d75140db474c46d
parent d4b9778f
......@@ -17,7 +17,6 @@
#pragma once
#include <atomic>
#include <cmath>
#include <cstring>
#include <memory>
#include <type_traits>
......@@ -152,21 +151,12 @@ class LockFreeRingBuffer {
/// Returns a Cursor pointing to the first write that has not occurred yet.
Cursor currentHead() noexcept { return Cursor(ticket_.load()); }
/// Returns a Cursor pointing to a currently readable write.
/// skipFraction is a value in the [0, 1] range indicating how far into the
/// currently readable window to place the cursor. 0 means the
/// earliest readable write, 1 means the latest readable write (if any).
Cursor currentTail(double skipFraction = 0.0) noexcept {
assert(skipFraction >= 0.0 && skipFraction <= 1.0);
/// Returns a Cursor pointing to the earliest readable write.
Cursor currentTail() noexcept {
uint64_t ticket = ticket_.load();
uint64_t backStep = llround((1.0 - skipFraction) * capacity_);
// always try to move at least one step backward to something readable
backStep = std::max<uint64_t>(1, backStep);
// can't go back more steps than we've taken
backStep = std::min(ticket, backStep);
uint64_t backStep = std::min<uint64_t>(ticket, capacity_);
return Cursor(ticket - backStep);
}
......
......@@ -177,42 +177,6 @@ TEST(LockFreeRingBuffer, readerCanDetectSkips) {
cursor = rb.currentTail();
EXPECT_TRUE(rb.tryRead(result, cursor));
EXPECT_EQ(capacity * (rounds - 1), result);
cursor = rb.currentTail(1.0);
EXPECT_TRUE(rb.tryRead(result, cursor));
EXPECT_EQ((capacity * rounds) - 1, result);
}
TEST(LockFreeRingBuffer, currentTailRange) {
const int capacity = 4;
LockFreeRingBuffer<int> rb(capacity);
// Workaround for template deduction failure
auto (&cursorValue)(value<int, std::atomic>);
// Empty buffer - everything points to 0
EXPECT_EQ(0, cursorValue(rb.currentTail(0)));
EXPECT_EQ(0, cursorValue(rb.currentTail(0.5)));
EXPECT_EQ(0, cursorValue(rb.currentTail(1)));
// Half-full
int val = 5;
rb.write(val);
rb.write(val);
EXPECT_EQ(0, cursorValue(rb.currentTail(0)));
EXPECT_EQ(1, cursorValue(rb.currentTail(1)));
// Full
rb.write(val);
rb.write(val);
EXPECT_EQ(0, cursorValue(rb.currentTail(0)));
EXPECT_EQ(3, cursorValue(rb.currentTail(1)));
auto midvalue = cursorValue(rb.currentTail(0.5));
// both rounding behaviours are acceptable
EXPECT_TRUE(midvalue == 1 || midvalue == 2);
}
TEST(LockFreeRingBuffer, cursorFromWrites) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment