Zero  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AsyncRingBuffer Class Reference

#include <ringbuffer.h>

Public Member Functions

char * producerRequest ()
 
void producerRelease ()
 
char * consumerRequest ()
 
void consumerRelease ()
 
bool isFull ()
 
bool isEmpty ()
 
size_t getBlockSize ()
 
size_t getBlockCount ()
 
void set_finished (bool f=true)
 
bool * get_finished ()
 
bool isFinished ()
 
 AsyncRingBuffer (size_t bsize, size_t bcount)
 
 ~AsyncRingBuffer ()
 

Private Member Functions

bool wait (pthread_cond_t *)
 
void increment (int &p, bool &parity)
 

Private Attributes

char * buf
 
int begin
 
int end
 
bool bparity
 
bool eparity
 
bool finished
 
const size_t blockSize
 
const size_t blockCount
 
pthread_mutex_t mutex
 
pthread_cond_t notEmpty
 
pthread_cond_t notFull
 

Detailed Description

Simple implementation of a circular IO buffer for the archiver reader, which reads log records from the recovery log, and the archiver writer, which writes sorted runs to output files. Despite being designed for log archiving, it should support more general use cases.

The buffer supports only one consumer and one producer, which makes synchronization much simpler. In the case of a read buffer, the producer is the reader thread and the consumer is the sorting thread (with the log scanner), which inserts log records into the heap for replacement selection. In a write buffer, the producer is the sorting thread, while the consumer writes blocks to the current run.

The allocation of buffer blocks (by both producers and consumers) must be done in two stages: 1) Request a block, waiting on a condvar if buffer is empty/full 2) Once done, release it to the other producer/consumer thread

Requests could be implemented in a single step if we copy the block to the caller's memory, but we want to avoid that. Again, this assumes that only one thread is consuming and one is releasing, and that they request and release blocks in an ordered behavior.

Author: Caetano Sauer

Constructor & Destructor Documentation

§ AsyncRingBuffer()

AsyncRingBuffer::AsyncRingBuffer ( size_t  bsize,
size_t  bcount 
)
inline

§ ~AsyncRingBuffer()

AsyncRingBuffer::~AsyncRingBuffer ( )
inline

Member Function Documentation

§ consumerRelease()

void AsyncRingBuffer::consumerRelease ( )
inline

§ consumerRequest()

char * AsyncRingBuffer::consumerRequest ( )
inline

§ get_finished()

bool* AsyncRingBuffer::get_finished ( )
inline

§ getBlockCount()

size_t AsyncRingBuffer::getBlockCount ( )
inline

§ getBlockSize()

size_t AsyncRingBuffer::getBlockSize ( )
inline

§ increment()

void AsyncRingBuffer::increment ( int &  p,
bool &  parity 
)
inlineprivate

§ isEmpty()

bool AsyncRingBuffer::isEmpty ( )
inline

§ isFinished()

bool AsyncRingBuffer::isFinished ( )
inline

§ isFull()

bool AsyncRingBuffer::isFull ( )
inline

§ producerRelease()

void AsyncRingBuffer::producerRelease ( )
inline

§ producerRequest()

char * AsyncRingBuffer::producerRequest ( )
inline

§ set_finished()

void AsyncRingBuffer::set_finished ( bool  f = true)
inline

§ wait()

bool AsyncRingBuffer::wait ( pthread_cond_t *  cond)
inlineprivate

Member Data Documentation

§ begin

int AsyncRingBuffer::begin
private

§ blockCount

const size_t AsyncRingBuffer::blockCount
private

§ blockSize

const size_t AsyncRingBuffer::blockSize
private

§ bparity

bool AsyncRingBuffer::bparity
private

§ buf

char* AsyncRingBuffer::buf
private

§ end

int AsyncRingBuffer::end
private

§ eparity

bool AsyncRingBuffer::eparity
private

§ finished

bool AsyncRingBuffer::finished
private

§ mutex

pthread_mutex_t AsyncRingBuffer::mutex
private

§ notEmpty

pthread_cond_t AsyncRingBuffer::notEmpty
private

§ notFull

pthread_cond_t AsyncRingBuffer::notFull
private

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