CernVM-FS
2.12.0
|
#include <ring_buffer.h>
Public Types | |
typedef size_t | ObjectHandle_t |
Public Member Functions | |
RingBuffer (size_t total_size) | |
~RingBuffer () | |
ObjectHandle_t | PushFront (const void *obj, size_t size) |
ObjectHandle_t | RemoveBack () |
size_t | GetObjectSize (ObjectHandle_t handle) const |
void | CopyObject (ObjectHandle_t handle, void *to) const |
void | CopySlice (ObjectHandle_t handle, size_t size, size_t offset, void *to) const |
size_t | GetMaxObjectSize () const |
bool | HasSpaceFor (size_t size) const |
size_t | free_space () const |
Static Public Attributes | |
static const ObjectHandle_t | kInvalidObjectHandle = size_t(-1) |
Private Member Functions | |
void | Put (const void *data, size_t size) |
void | Get (size_t from, size_t size, void *to) const |
void | Shrink (size_t by) |
Private Member Functions inherited from SingleCopy | |
SingleCopy () | |
Private Attributes | |
const size_t | total_size_ |
size_t | free_space_ |
size_t | front_ |
size_t | back_ |
unsigned char * | buffer_ |
This file is part of the CernVM File System. A ring buffer that allows appending objects to the front and removing objects from the back. In the memory area, we prepend the object data with the size of the object.
Definition at line 17 of file ring_buffer.h.
typedef size_t RingBuffer::ObjectHandle_t |
The offset in buffer_
Definition at line 22 of file ring_buffer.h.
|
explicit |
RingBuffer::~RingBuffer | ( | ) |
Definition at line 28 of file ring_buffer.cc.
void RingBuffer::CopyObject | ( | ObjectHandle_t | handle, |
void * | to | ||
) | const |
Note that we cannot just return a pointer because an object may be split between the end and the beginning of the backing memory area
Definition at line 103 of file ring_buffer.cc.
void RingBuffer::CopySlice | ( | ObjectHandle_t | handle, |
size_t | size, | ||
size_t | offset, | ||
void * | to | ||
) | const |
Copies a sub range of the object
Definition at line 111 of file ring_buffer.cc.
|
inline |
Definition at line 64 of file ring_buffer.h.
|
private |
Copies data from the buffer to the memory area "to". The memory area has to be big enough. Takes care of a potential buffer wrap.
Definition at line 49 of file ring_buffer.cc.
Referenced by CopyObject(), CopySlice(), and GetObjectSize().
|
inline |
Definition at line 59 of file ring_buffer.h.
size_t RingBuffer::GetObjectSize | ( | ObjectHandle_t | handle | ) | const |
The passed object handle must be valid
Definition at line 68 of file ring_buffer.cc.
Referenced by CopyObject(), and RemoveBack().
|
inline |
Definition at line 60 of file ring_buffer.h.
RingBuffer::ObjectHandle_t RingBuffer::PushFront | ( | const void * | obj, |
size_t | size | ||
) |
Returns kInvalidObjectHandle if there is not enough space to insert the object.
Definition at line 76 of file ring_buffer.cc.
|
private |
Writes data into the ring buffer at front_, taking care of a potential buffer wrap. Assumes that the buffer has enough space.
Definition at line 33 of file ring_buffer.cc.
Referenced by PushFront().
RingBuffer::ObjectHandle_t RingBuffer::RemoveBack | ( | ) |
Returns the handle of the remove object or kInvalidObjectHandle if the ring buffer is empty
Definition at line 92 of file ring_buffer.cc.
|
private |
Moves the back_ pointer forward, taking care of potential buffer wraps
Definition at line 62 of file ring_buffer.cc.
Referenced by RemoveBack().
|
private |
Pointer to the back of the memory buffer, in [0, size_ - 1]
Definition at line 97 of file ring_buffer.h.
Referenced by RemoveBack(), and Shrink().
|
private |
The memory area backing the ring buffer
Definition at line 101 of file ring_buffer.h.
Referenced by Get(), Put(), and ~RingBuffer().
|
private |
Size in bytes of the unused space in the buffer
Definition at line 89 of file ring_buffer.h.
Referenced by free_space(), HasSpaceFor(), PushFront(), Put(), and Shrink().
|
private |
Pointer to the front of the memory buffer, in [0, size_ - 1]
Definition at line 93 of file ring_buffer.h.
Referenced by PushFront(), and Put().
|
static |
This file is part of the CernVM File System.
Definition at line 23 of file ring_buffer.h.
Referenced by PushFront().
|
private |
Size in bytes of the memory area backing the ring buffer
Definition at line 85 of file ring_buffer.h.
Referenced by CopyObject(), CopySlice(), Get(), GetMaxObjectSize(), GetObjectSize(), Put(), RingBuffer(), Shrink(), and ~RingBuffer().