Public Member Functions | Private Attributes | List of all members
ConcBuf Class Reference

ConcBuf is a class that implements a circular buffer for concurrent access from two distinct threads. More...

#include <ConcurrentBuffer.h>

Public Member Functions

 ConcBuf (Blocks_Type aBuf, Samples_Type sBuf, std::string pbufname)
 Concurrent buffer (concbuf) constructor. More...
 
 ~ConcBuf ()
 
std::complex< double > * RequestWriting ()
 snBlocks call RequestWriting to block the next concbuf block for write access More...
 
void ReleaseWriting (Samples_Type aDataWritten, bool WFinished)
 releases write lock to a concbuf block More...
 
std::complex< double > * RequestReading (Samples_Type *nToRead)
 request read lock to next concbuf block More...
 
bool ReleaseReading ()
 releases read lock More...
 

Private Attributes

std::string bufname
 
std::complex< double > * Buf
 
Samples_Type BufSize
 
Blocks_Type maxBuf
 
Samples_TypenToBeRead
 
Blocks_Type nBufProducer
 
Blocks_Type nBufConsumer
 
Blocks_Type WFinished
 
QSemaphore freeBuffers
 
QSemaphore usedBuffers
 
int WaitTimeout
 

Detailed Description

ConcBuf is a class that implements a circular buffer for concurrent access from two distinct threads.

The constructor sets up a concbuf consisting of an amount of arrays, called concbuf blocks. The concbuffer is shared between two snBlocks. One snBlock starts to write to the concbuffer and fills up the concbuf blocks one after another. If all concbuf blocks are full, the process has to wait. The successive snBlock in the simulation chain starts to read from the concbuffer until there are no new concbuf blocks left.

The writing process requests its need to write to a concbuffer with the function RequestWriting. This function returns a pointer to the first element of the respective concbuf block. After filling this concbuf block, the writing process terminates the writing with ReleaseWriting.

The reading process requests its wish for reading from the concbuffer by calling RequestReading. It gets a pointer to the concbuf block and and amount of elements to read. It releases the read lock with ReleaseReading.

Constructor & Destructor Documentation

ConcBuf::ConcBuf ( Blocks_Type  aBuf,
Samples_Type  sBuf,
std::string  pbufname 
)

Concurrent buffer (concbuf) constructor.

Parameters
<longaBuf> amount of concbuf blocks (arrays) per concbuf
<Samples_TypesBuf> length of one concbuf block
<std::stringpbufname> name of the concbuffer
ConcBuf::~ConcBuf ( )

Member Function Documentation

bool ConcBuf::ReleaseReading ( )

releases read lock

void ConcBuf::ReleaseWriting ( Samples_Type  aDataWritten,
bool  WFinished 
)

releases write lock to a concbuf block

Parameters
<longaDataWritten> amount of data written
<longWFinished> 0 for continued operation. 1 for indication that this concbuf block was the last one to write to.
std::complex< double > * ConcBuf::RequestReading ( Samples_Type nToRead)

request read lock to next concbuf block

Parameters
<Samples_Type*nToRead> this variable will contain the amount of elements that can be read from the concbuf block
Returns
pointer to the first element of the concbuf block
std::complex< double > * ConcBuf::RequestWriting ( )

snBlocks call RequestWriting to block the next concbuf block for write access

Returns
pointer to the first element of a concbuf block which is being locked for writing.

Member Data Documentation

std::complex<double>* ConcBuf::Buf
private
std::string ConcBuf::bufname
private
Samples_Type ConcBuf::BufSize
private
QSemaphore ConcBuf::freeBuffers
private
Blocks_Type ConcBuf::maxBuf
private
Blocks_Type ConcBuf::nBufConsumer
private
Blocks_Type ConcBuf::nBufProducer
private
Samples_Type* ConcBuf::nToBeRead
private
QSemaphore ConcBuf::usedBuffers
private
int ConcBuf::WaitTimeout
private
Blocks_Type ConcBuf::WFinished
private

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