Commit 15ee6d71 authored by Chad Austin's avatar Chad Austin Committed by Facebook GitHub Bot

always copy into LockFreeRingBuffer writes

Summary:
In preparation for making LockFreeRingBuffer trivial-only, remove the
ability to convert types during reads and writes.

Reviewed By: yfeldblum

Differential Revision: D27684584

fbshipit-source-id: 092009b2852d000fa3821756d1ec4bfd2bf002c8
parent 2b9c0388
...@@ -198,14 +198,14 @@ class RingBufferSlot { ...@@ -198,14 +198,14 @@ class RingBufferSlot {
explicit RingBufferSlot() noexcept : sequencer_(), data() {} explicit RingBufferSlot() noexcept : sequencer_(), data() {}
template <typename V> template <typename V>
void write(const uint32_t turn, V& value) noexcept { void write(const uint32_t turn, const V& value) noexcept {
Atom<uint32_t> cutoff(0); Atom<uint32_t> cutoff(0);
sequencer_.waitForTurn(turn * 2, cutoff, false); sequencer_.waitForTurn(turn * 2, cutoff, false);
// Change to an odd-numbered turn to indicate write in process // Change to an odd-numbered turn to indicate write in process
sequencer_.completeTurn(turn * 2); sequencer_.completeTurn(turn * 2);
data = std::move(value); data = value;
sequencer_.completeTurn(turn * 2 + 1); sequencer_.completeTurn(turn * 2 + 1);
// At (turn + 1) * 2 // At (turn + 1) * 2
} }
......
...@@ -250,44 +250,4 @@ TEST(LockFreeRingBuffer, moveBackwardsCanFail) { ...@@ -250,44 +250,4 @@ TEST(LockFreeRingBuffer, moveBackwardsCanFail) {
EXPECT_FALSE(cursor.moveBackward()); // moving back does nothing EXPECT_FALSE(cursor.moveBackward()); // moving back does nothing
} }
TEST(LockFreeRingBuffer, writeReadDifferentType) {
struct FixedBuffer {
char data_[1024];
FixedBuffer() noexcept { data_[0] = '\0'; }
FixedBuffer& operator=(std::string&& data) {
strncpy(data_, data.c_str(), sizeof(data_) - 1);
return (*this);
}
};
struct StringBuffer {
char data_[1024];
StringBuffer() noexcept { data_[0] = '\0'; }
StringBuffer& operator=(FixedBuffer& data) {
static_assert(
sizeof(data_) == sizeof(data.data_),
"FixedBuffer::data_ size must match StringBuffer::data_");
memcpy(data_, data.data_, sizeof(data.data_));
return (*this);
}
};
std::string str("Test");
const int capacity = 3;
LockFreeRingBuffer<FixedBuffer> rb(capacity);
rb.write(str);
auto cursor = rb.currentTail();
StringBuffer result;
EXPECT_TRUE(rb.tryRead(result, cursor));
EXPECT_EQ(str, result.data_);
}
} // namespace folly } // namespace folly
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