proxygen
|
#include <LockFreeRingBuffer.h>
Classes | |
struct | Cursor |
Public Member Functions | |
LockFreeRingBuffer (uint32_t capacity) noexcept | |
void | write (T &value) noexcept |
Cursor | writeAndGetCursor (T &value) noexcept |
bool | tryRead (T &dest, const Cursor &cursor) noexcept |
bool | waitAndTryRead (T &dest, const Cursor &cursor) noexcept |
Cursor | currentHead () noexcept |
Returns a Cursor pointing to the first write that has not occurred yet. More... | |
Cursor | currentTail (double skipFraction=0.0) noexcept |
~LockFreeRingBuffer () | |
Private Member Functions | |
uint32_t | idx (uint64_t ticket) noexcept |
uint32_t | turn (uint64_t ticket) noexcept |
Private Attributes | |
const uint32_t | capacity_ |
const std::unique_ptr< detail::RingBufferSlot< T, Atom >[]> | slots_ |
Atom< uint64_t > | ticket_ |
LockFreeRingBuffer<T> is a fixed-size, concurrent ring buffer with the following semantics:
In this sense, reads from this buffer are best-effort but writes are guaranteed.
Another way to think about this is as an unbounded stream of writes. The buffer contains the last <capacity> writes but readers can attempt to read any part of the stream, even outside this window. The read API takes a Cursor that can point anywhere in this stream of writes. Reads from the "future" can optionally block but reads from the "past" will always fail.
Definition at line 59 of file LockFreeRingBuffer.h.
|
inlineexplicitnoexcept |
Definition at line 99 of file LockFreeRingBuffer.h.
|
inline |
Definition at line 162 of file LockFreeRingBuffer.h.
|
inlinenoexcept |
Returns a Cursor pointing to the first write that has not occurred yet.
Definition at line 139 of file LockFreeRingBuffer.h.
Referenced by folly::runWritesNeverFail(), and folly::TEST().
|
inlinenoexcept |
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).
Definition at line 147 of file LockFreeRingBuffer.h.
References min, ticket, and uint64_t.
Referenced by folly::TEST().
|
inlineprivatenoexcept |
|
inlinenoexcept |
Read the value at the cursor. Returns true if the read succeeded, false otherwise. If the return value is false, dest is to be considered partially read and in an inconsistent state. Readers are advised to discard it.
Definition at line 126 of file LockFreeRingBuffer.h.
References upload::dest.
Referenced by folly::TEST().
|
inlineprivatenoexcept |
|
inlinenoexcept |
Read the value at the cursor or block if the write has not occurred yet. Returns true if the read succeeded, false otherwise. If the return value is false, dest is to be considered partially read and in an inconsistent state. Readers are advised to discard it.
Definition at line 134 of file LockFreeRingBuffer.h.
References upload::dest.
Referenced by folly::TEST().
|
inlinenoexcept |
Perform a single write of an object of type T. Writes can block iff a previous writer has not yet completed a write for the same slot (before the most recent wrap-around).
Definition at line 107 of file LockFreeRingBuffer.h.
References ticket, uint64_t, and folly::value().
Referenced by folly::runReader(), and folly::TEST().
|
inlinenoexcept |
Perform a single write of an object of type T. Writes can block iff a previous writer has not yet completed a write for the same slot (before the most recent wrap-around). Returns a Cursor pointing to the just-written T.
Definition at line 116 of file LockFreeRingBuffer.h.
References ticket, uint64_t, and folly::value().
Referenced by folly::TEST().
|
private |
Definition at line 165 of file LockFreeRingBuffer.h.
|
private |
Definition at line 167 of file LockFreeRingBuffer.h.
|
private |
Definition at line 169 of file LockFreeRingBuffer.h.