#include <pipeline.h>
Inheritance diagram for rpa::pipebase< Container, CondVar >:
Public Types | |
typedef CondVar::mutex_type | mutex_type |
typedef container_traits< Container >::iterator | iterator |
Public Member Functions | |
void | check (void) const |
template<class ThreadBase> | |
shutter_thread< ThreadBase > | make_shutter (ThreadBase *ptrThr) |
Helper function for creating a shutter_thread out of any thread. | |
pipebase (mutex_type *mtxPtr) | |
pipebase (mutex_type *mtxPtr, size_t maxNb) | |
template<class Iter> | |
pipebase (mutex_type *mtxPtr, Iter begIter, Iter endIter, bool shutFlag) | |
pipebase (mutex_type *mtxPtr, const Container &aCont, bool shutFlag) | |
void | notify_reading_threads (size_t nbInsertedElements) |
void | shut (void) |
bool | is_shut (void) const |
If set, waiting threads get the last elements and no longer wait. | |
~pipebase () | |
Static Public Member Functions | |
template<class DrvPip> | |
static bool | wait_data (DrvPip *drvThis) |
Waits for data to read or if the pipe is shut. | |
Public Attributes | |
size_t | _nbThrWaitToRead |
GccNoFriend(protected) iterator | _it_rd |
iterator | _it_beg |
iterator | _it_end |
Protected Attributes | |
CondVar | _condNotEmptyOrShut |
Private Types | |
typedef pipe_container< Container > | pip_cont_t |
Private Member Functions | |
void | init (mutex_type *mtxPtr, bool shutFlag=false) |
Simple init called by all constructors. | |
Classes | |
class | shutter_thread |
This class behaves like a thread proxy. Its use is optional. More... |
typedef container_traits< Container >::iterator rpa::pipebase< Container, CondVar >::iterator |
Reimplemented from rpa::pipe_container< Container >.
Reimplemented in rpa::pipe_circular< Container, CondVar >, rpa::pipe_archiver< Container, CondVar >, rpa::pipe_arc_base< Container, CondVar >, rpa::pipe_arc_aux< Container, CondVar, insertInvalidatesIterators >, rpa::pipe_arc_aux< Container, CondVar, true >, and rpa::pipe_arc_aux< Container, CondVar, rpa::insert_invalidates_iterators< Container >::value >.
typedef CondVar::mutex_type rpa::pipebase< Container, CondVar >::mutex_type |
Reimplemented in rpa::pipe_circular< Container, CondVar >, rpa::pipe_archiver< Container, CondVar >, rpa::pipe_arc_base< Container, CondVar >, rpa::pipe_arc_aux< Container, CondVar, insertInvalidatesIterators >, rpa::pipe_arc_aux< Container, CondVar, true >, and rpa::pipe_arc_aux< Container, CondVar, rpa::insert_invalidates_iterators< Container >::value >.
typedef pipe_container< Container > rpa::pipebase< Container, CondVar >::pip_cont_t [private] |
rpa::pipebase< Container, CondVar >::pipebase | ( | mutex_type * | mtxPtr | ) | [inline] |
The container is set to the proper size. If this is a plain array, we do nothing. We could do a lazy-resizing, only when it is necessary, but there is no point to wait : If a given size is necessary, why not resizing now ? More: By setting the right size immediately, we ensure that the iterators are always valid. On the other hand, the real shame of it is that we must always pay the price of a full allocation even for a couple of data. (This is also true for output buffers obuf_iterator). To compensate this, a buffer can be reused, once allocated. This default constructor can be used only for unlimited pipes.
rpa::pipebase< Container, CondVar >::pipebase | ( | mutex_type * | mtxPtr, | |
size_t | maxNb | |||
) | [inline] |
rpa::pipebase< Container, CondVar >::pipebase | ( | mutex_type * | mtxPtr, | |
Iter | begIter, | |||
Iter | endIter, | |||
bool | shutFlag | |||
) | [inline] |
rpa::pipebase< Container, CondVar >::pipebase | ( | mutex_type * | mtxPtr, | |
const Container & | aCont, | |||
bool | shutFlag | |||
) | [inline] |
rpa::pipebase< Container, CondVar >::~pipebase | ( | ) | [inline] |
The destructor waits until all writers have left, and the readers have read everything. QUESTION: HOW DO WE WAIT ? HOW IS IT DONE ?
void rpa::pipebase< Container, CondVar >::check | ( | void | ) | const [inline] |
This checks that the iterator of the next element to read, is between the beginning and the end of the underlying container. The distance are signed integers to check whether they are negative.
Reimplemented in rpa::pipe_circular< Container, CondVar >.
void rpa::pipebase< Container, CondVar >::init | ( | mutex_type * | mtxPtr, | |
bool | shutFlag = false | |||
) | [inline, private] |
Simple init called by all constructors.
bool rpa::pipebase< Container, CondVar >::is_shut | ( | void | ) | const [inline] |
If set, waiting threads get the last elements and no longer wait.
shutter_thread< ThreadBase > rpa::pipebase< Container, CondVar >::make_shutter | ( | ThreadBase * | ptrThr | ) | [inline] |
Helper function for creating a shutter_thread out of any thread.
void rpa::pipebase< Container, CondVar >::notify_reading_threads | ( | size_t | nbInsertedElements | ) | [inline] |
When 'append' inserts many elements, it must notify reading threads:
void rpa::pipebase< Container, CondVar >::shut | ( | void | ) | [inline] |
When this flag is set, a reader thread will not wait if beg==end. Can be called even if there are some more elements to process. They will be processed anyway.
Notifies all threads waiting for values, or for the pipe to be shut.
static bool rpa::pipebase< Container, CondVar >::wait_data | ( | DrvPip * | drvThis | ) | [inline, static] |
Waits for data to read or if the pipe is shut.
Does not need virtuals for data_ready. The mutex must be locked. It might be worth using an object for the counters of waiting threads, which would be decremented even if an exception were thrown by wait().
CondVar rpa::pipebase< Container, CondVar >::_condNotEmptyOrShut [protected] |
This avoids to make a condition broadcast: Signal is enough. It would be possible to have to kind of conditions as long as they are based on the same mutex.
iterator rpa::pipebase< Container, CondVar >::_it_beg |
iterator rpa::pipebase< Container, CondVar >::_it_end |
GccNoFriend (protected) iterator rpa::pipebase< Container, CondVar >::_it_rd |
size_t rpa::pipebase< Container, CondVar >::_nbThrWaitToRead |
This is used for counting the threads waiting for data or shut. Used for debugging but also for notifying that the pipe is shut.