Public Member Functions

JackCpp::RingBuffer< Type > Class Template Reference

This template class wraps the Jack lock-free ringbuffer. More...

#include <jackringbuffer.hpp>

List of all members.

Public Member Functions

 RingBuffer (size_t size, bool mlock=false)
 The Constructor.
 ~RingBuffer ()
 The Destructor.
size_t length ()
 Get the total length of the ring buffer.
size_t getReadSpace ()
 Get the number of items that can be read at this time.
size_t getWriteSpace ()
 Get the number of items that can be written at this time.
void read (Type &dest)
 Read into dest.
void read (Type *dest, unsigned cnt)
 Read into an array.
void write (Type src)
 Write into the ring buffer.
void write (Type *src, unsigned int cnt)
 Write an array of values into the ring buffer.
void reset ()
 Reset.

Detailed Description

template<typename Type>
class JackCpp::RingBuffer< Type >

This template class wraps the Jack lock-free ringbuffer.

This class creates a lock-free ring buffer that accepts a specific data type.

The key attribute of a ringbuffer is that it can be safely accessed by two threads simultaneously -- one reading from the buffer and the other writing to it -- without using any synchronization or mutual exclusion primitives. For this to work correctly, there can only be a single reader and a single writer thread. Their identities cannot be interchanged.

Author:
Alex Norman

Constructor & Destructor Documentation

template<typename Type>
JackCpp::RingBuffer< Type >::RingBuffer ( size_t  size,
bool  mlock = false 
) [inline]

The Constructor.

Parameters:
size the number of items that the ring buffer should be able to hold
mlock a boolean indicating whether or not the ring buffer should be locked in memory

Member Function Documentation

template<typename Type>
void JackCpp::RingBuffer< Type >::read ( Type &  dest  )  [inline]

Read into dest.

Read from the buffer into a variable.

Parameters:
dest an item to be read into
template<typename Type>
void JackCpp::RingBuffer< Type >::read ( Type *  dest,
unsigned  cnt 
) [inline]

Read into an array.

Read from the buffer into an array.

Parameters:
dest an array to be read into
cnt the number of elements to read into this array
template<typename Type>
void JackCpp::RingBuffer< Type >::reset (  )  [inline]

Reset.

This is not threadsafe. This resets the read and write pointers, effectively making the ring buffer empty.

template<typename Type>
void JackCpp::RingBuffer< Type >::write ( Type *  src,
unsigned int  cnt 
) [inline]

Write an array of values into the ring buffer.

Parameters:
src an array of values to write
cnt the number of items from the array to write into our buffer
template<typename Type>
void JackCpp::RingBuffer< Type >::write ( Type  src  )  [inline]

Write into the ring buffer.

Parameters:
src the value to write

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