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.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PageCircularBuffer Class Reference

#include <PageCircularBuffer.h>

+ Collaboration diagram for PageCircularBuffer:

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

PDBPagePtrgetPageArray ()
 
unsigned int getPageArrayHead ()
 
unsigned int getPageArrayTail ()
 
unsigned int getMaxArraySize ()
 
int initArray ()
 

Private Attributes

PDBPagePtrpageArray
 
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
 

Detailed Description

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.

Constructor & Destructor Documentation

PageCircularBuffer::PageCircularBuffer ( unsigned int  bufferSize,
pdb::PDBLoggerPtr  logger 
)

Definition at line 30 of file PageCircularBuffer.cc.

+ Here is the call graph for this function:

PageCircularBuffer::~PageCircularBuffer ( )

Definition at line 40 of file PageCircularBuffer.cc.

Member Function Documentation

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.

+ Here is the call graph for this function:

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.

unsigned int PageCircularBuffer::getMaxArraySize ( )
inlineprotected

Return the maximum size of the concurrent blocking circular buffer.

Definition at line 115 of file PageCircularBuffer.h.

PDBPagePtr* PageCircularBuffer::getPageArray ( )
inlineprotected

Return the page array used to construct the concurrent blocking circular buffer.

Definition at line 94 of file PageCircularBuffer.h.

unsigned int PageCircularBuffer::getPageArrayHead ( )
inlineprotected

Return the head index to the concurrent blocking circular buffer.

Definition at line 101 of file PageCircularBuffer.h.

unsigned int PageCircularBuffer::getPageArrayTail ( )
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.

+ Here is the caller graph for this function:

int PageCircularBuffer::initArray ( )
protected

Initialize the concurrent blocking circular buffer.

Definition at line 47 of file PageCircularBuffer.cc.

+ Here is the caller graph for this function:

bool PageCircularBuffer::isClosed ( )
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.

+ Here is the caller graph for this function:

bool PageCircularBuffer::isFull ( )

If the buffer is full, return true, otherwise, return false.

Definition at line 114 of file PageCircularBuffer.cc.

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

Member Data Documentation

pthread_mutex_t PageCircularBuffer::addPageMutex
private

Definition at line 131 of file PageCircularBuffer.h.

bool PageCircularBuffer::closed
private

Definition at line 133 of file PageCircularBuffer.h.

pthread_cond_t PageCircularBuffer::cond
private

Definition at line 132 of file PageCircularBuffer.h.

pdb::PDBLoggerPtr PageCircularBuffer::logger
private

Definition at line 126 of file PageCircularBuffer.h.

unsigned int PageCircularBuffer::maxArraySize
private

Definition at line 127 of file PageCircularBuffer.h.

pthread_mutex_t PageCircularBuffer::mutex
private

Definition at line 130 of file PageCircularBuffer.h.

PDBPagePtr* PageCircularBuffer::pageArray
private

Definition at line 125 of file PageCircularBuffer.h.

unsigned int PageCircularBuffer::pageArrayHead
private

Definition at line 128 of file PageCircularBuffer.h.

unsigned int PageCircularBuffer::pageArrayTail
private

Definition at line 129 of file PageCircularBuffer.h.


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