CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RingBuffer Class Reference

#include <ring_buffer.h>

Inheritance diagram for RingBuffer:
Collaboration diagram for RingBuffer:

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_
 

Detailed Description

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.

Member Typedef Documentation

The offset in buffer_

Definition at line 22 of file ring_buffer.h.

Constructor & Destructor Documentation

RingBuffer::RingBuffer ( size_t  total_size)
explicit

Definition at line 17 of file ring_buffer.cc.

Here is the call graph for this function:

RingBuffer::~RingBuffer ( )

Definition at line 28 of file ring_buffer.cc.

Member Function Documentation

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.

Here is the call graph for this function:

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.

Here is the call graph for this function:

size_t RingBuffer::free_space ( ) const
inline

Definition at line 64 of file ring_buffer.h.

void RingBuffer::Get ( size_t  from,
size_t  size,
void *  to 
) const
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().

Here is the caller graph for this function:

size_t RingBuffer::GetMaxObjectSize ( ) const
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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool RingBuffer::HasSpaceFor ( size_t  size) const
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.

Here is the call graph for this function:

void RingBuffer::Put ( const void *  data,
size_t  size 
)
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().

Here is the caller graph for this function:

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.

Here is the call graph for this function:

void RingBuffer::Shrink ( size_t  by)
private

Moves the back_ pointer forward, taking care of potential buffer wraps

Definition at line 62 of file ring_buffer.cc.

Referenced by RemoveBack().

Here is the caller graph for this function:

Member Data Documentation

size_t RingBuffer::back_
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().

unsigned char* RingBuffer::buffer_
private

The memory area backing the ring buffer

Definition at line 101 of file ring_buffer.h.

Referenced by Get(), Put(), and ~RingBuffer().

size_t RingBuffer::free_space_
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().

size_t RingBuffer::front_
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().

const RingBuffer::ObjectHandle_t RingBuffer::kInvalidObjectHandle = size_t(-1)
static

This file is part of the CernVM File System.

Definition at line 23 of file ring_buffer.h.

Referenced by PushFront().

const size_t RingBuffer::total_size_
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().


The documentation for this class was generated from the following files: