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_Type * | nToBeRead |
Blocks_Type | nBufProducer |
Blocks_Type | nBufConsumer |
Blocks_Type | WFinished |
QSemaphore | freeBuffers |
QSemaphore | usedBuffers |
int | WaitTimeout |
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.
ConcBuf::ConcBuf | ( | Blocks_Type | aBuf, |
Samples_Type | sBuf, | ||
std::string | pbufname | ||
) |
Concurrent buffer (concbuf) constructor.
<long | aBuf> amount of concbuf blocks (arrays) per concbuf |
<Samples_Type | sBuf> length of one concbuf block |
<std::string | pbufname> name of the concbuffer |
ConcBuf::~ConcBuf | ( | ) |
bool ConcBuf::ReleaseReading | ( | ) |
releases read lock
void ConcBuf::ReleaseWriting | ( | Samples_Type | aDataWritten, |
bool | WFinished | ||
) |
releases write lock to a concbuf block
<long | aDataWritten> amount of data written |
<long | WFinished> 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
<Samples_Type | *nToRead> this variable will contain the amount of elements that can be read from the concbuf block |
std::complex< double > * ConcBuf::RequestWriting | ( | ) |
snBlocks call RequestWriting to block the next concbuf block for write access
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |