|
Zero
0.1.0
|
#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 |
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
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
1.8.12