A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
|
#include <PageCircularBuffer.h>
Public Member Functions | |
PageCircularBuffer (unsigned int bufferSize, pdb::PDBLoggerPtr logger) | |
~PageCircularBuffer () | |
int | addPageToTail (PDBPagePtr page) |
PDBPagePtr | popPageFromHead () |
bool | isFull () |
bool | isEmpty () |
unsigned int | getSize () |
void | close () |
void | open () |
bool | isClosed () |
Protected Member Functions | |
PDBPagePtr * | getPageArray () |
unsigned int | getPageArrayHead () |
unsigned int | getPageArrayTail () |
unsigned int | getMaxArraySize () |
int | initArray () |
Private Attributes | |
PDBPagePtr * | pageArray |
pdb::PDBLoggerPtr | logger |
unsigned int | maxArraySize |
unsigned int | pageArrayHead |
unsigned int | pageArrayTail |
pthread_mutex_t | mutex |
pthread_mutex_t | addPageMutex |
pthread_cond_t | cond |
bool | closed |
This class implements a concurrent blocking circular buffer for producer-consumer problems. The consumer threads will wait until there are pages available in the buffer. The producer threads will wait until there are rooms available in the buffer to push back new pages.
Definition at line 37 of file PageCircularBuffer.h.
PageCircularBuffer::PageCircularBuffer | ( | unsigned int | bufferSize, |
pdb::PDBLoggerPtr | logger | ||
) |
PageCircularBuffer::~PageCircularBuffer | ( | ) |
Definition at line 40 of file PageCircularBuffer.cc.
int PageCircularBuffer::addPageToTail | ( | PDBPagePtr | page | ) |
Add page to the tail of the circular buffer. If the buffer is full, it will block until there is new room in the buffer.
Definition at line 65 of file PageCircularBuffer.cc.
void PageCircularBuffer::close | ( | ) |
Close the buffer. If the buffer is empty now, notify all consumer threads that the buffer is closed.
Definition at line 132 of file PageCircularBuffer.cc.
|
inlineprotected |
Return the maximum size of the concurrent blocking circular buffer.
Definition at line 115 of file PageCircularBuffer.h.
|
inlineprotected |
Return the page array used to construct the concurrent blocking circular buffer.
Definition at line 94 of file PageCircularBuffer.h.
|
inlineprotected |
Return the head index to the concurrent blocking circular buffer.
Definition at line 101 of file PageCircularBuffer.h.
|
inlineprotected |
Return the tail index to the concurrent blocking circular buffer.
Definition at line 108 of file PageCircularBuffer.h.
unsigned int PageCircularBuffer::getSize | ( | ) |
Return the current size of the circular buffer.
Definition at line 128 of file PageCircularBuffer.cc.
|
protected |
Initialize the concurrent blocking circular buffer.
Definition at line 47 of file PageCircularBuffer.cc.
|
inline |
If the buffer is closed, return true, otherwise, return false.
Definition at line 86 of file PageCircularBuffer.h.
bool PageCircularBuffer::isEmpty | ( | ) |
If the buffer is empty, return true, otherwise, return false.
Definition at line 119 of file PageCircularBuffer.cc.
bool PageCircularBuffer::isFull | ( | ) |
If the buffer is full, return true, otherwise, return false.
Definition at line 114 of file PageCircularBuffer.cc.
void PageCircularBuffer::open | ( | ) |
Open the buffer.
Definition at line 140 of file PageCircularBuffer.cc.
PDBPagePtr PageCircularBuffer::popPageFromHead | ( | ) |
Pop page from the head of the circular buffer. If the buffer is empty, it will block until there is new page added to in the buffer, or until the buffer is closed. If the buffer is empty while being closed, the function will return nullptr.
Definition at line 94 of file PageCircularBuffer.cc.
|
private |
Definition at line 131 of file PageCircularBuffer.h.
|
private |
Definition at line 133 of file PageCircularBuffer.h.
|
private |
Definition at line 132 of file PageCircularBuffer.h.
|
private |
Definition at line 126 of file PageCircularBuffer.h.
|
private |
Definition at line 127 of file PageCircularBuffer.h.
|
private |
Definition at line 130 of file PageCircularBuffer.h.
|
private |
Definition at line 125 of file PageCircularBuffer.h.
|
private |
Definition at line 128 of file PageCircularBuffer.h.
|
private |
Definition at line 129 of file PageCircularBuffer.h.