casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize > Class Template Reference

implementation of producer consumer model More...

#include <PThreadUtil.h>

Public Types

typedef
ProducerConsumerModelContext
< DataType, BufferSize > 
_Context
 

Public Member Functions

 ProducerConsumerModelContext (DataType const terminator)
 constructor More...
 
 ~ProducerConsumerModelContext ()
 destructor More...
 

Static Public Member Functions

static void produce (_Context *context, DataType item)
 production function More...
 
static bool consume (_Context *context, DataType *item)
 consumption function return false if no more products available otherwise return true More...
 
static void complete_production (_Context *context)
 it should be called when production complete More...
 
template<class T >
static void locked_print (T msg, _Context *context)
 utility More...
 

Private Member Functions

int lock ()
 
int unlock ()
 
int try_lock ()
 
int producer_wait ()
 
int producer_signal ()
 
int consumer_wait ()
 
int consumer_signal ()
 
bool buffer_is_full ()
 
bool buffer_is_empty ()
 
void producer_next ()
 
void consumer_next ()
 
void push_product (DataType item)
 
void pop_product (DataType *item)
 

Private Attributes

DataType const end_of_production_
 terminator data (product == end_of_production_) indicates that production is completed. More...
 
DataType buffer_ [BufferSize]
 
ssize_t num_product_in_buffer_
 
ssize_t producer_index_
 
ssize_t consumer_index_
 
Mutex mutex_
 
PCondition consumer_condition_
 
PCondition producer_condition_
 

Detailed Description

template<class DataType, ssize_t BufferSize>
class casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >

implementation of producer consumer model

Definition at line 104 of file PThreadUtil.h.

Member Typedef Documentation

template<class DataType , ssize_t BufferSize>
typedef ProducerConsumerModelContext<DataType, BufferSize> casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::_Context

Definition at line 106 of file PThreadUtil.h.

Constructor & Destructor Documentation

template<class DataType , ssize_t BufferSize>
casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::ProducerConsumerModelContext ( DataType const  terminator)
inline

constructor

std::cout << "end_of_production = " << end_of_production_ << std::endl;

Definition at line 161 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::~ProducerConsumerModelContext ( )
inline

destructor

Definition at line 169 of file PThreadUtil.h.

Member Function Documentation

template<class DataType , ssize_t BufferSize>
bool casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::buffer_is_empty ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
bool casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::buffer_is_full ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
static void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::complete_production ( _Context context)
inlinestatic

it should be called when production complete

Definition at line 156 of file PThreadUtil.h.

References casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::end_of_production_.

template<class DataType , ssize_t BufferSize>
static bool casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume ( _Context context,
DataType *  item 
)
inlinestatic
template<class DataType , ssize_t BufferSize>
void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_next ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_signal ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_wait ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::lock ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
template<class T >
static void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::locked_print ( msg,
_Context context 
)
inlinestatic
template<class DataType , ssize_t BufferSize>
void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::pop_product ( DataType *  item)
inlineprivate
template<class DataType , ssize_t BufferSize>
static void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce ( _Context context,
DataType  item 
)
inlinestatic
template<class DataType , ssize_t BufferSize>
void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_next ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_signal ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_wait ( )
inlineprivate
template<class DataType , ssize_t BufferSize>
void casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::push_product ( DataType  item)
inlineprivate
template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::try_lock ( )
inlineprivate

Definition at line 189 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
int casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::unlock ( )
inlineprivate

Member Data Documentation

template<class DataType , ssize_t BufferSize>
DataType casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::buffer_[BufferSize]
private

Definition at line 241 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
PCondition casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_condition_
private

Definition at line 246 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
ssize_t casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_index_
private

Definition at line 244 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
DataType const casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::end_of_production_
private

terminator data (product == end_of_production_) indicates that production is completed.

Definition at line 240 of file PThreadUtil.h.

Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::complete_production(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().

template<class DataType , ssize_t BufferSize>
Mutex casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::mutex_
private

Definition at line 245 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
ssize_t casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::num_product_in_buffer_
private

Definition at line 242 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
PCondition casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_condition_
private

Definition at line 247 of file PThreadUtil.h.

template<class DataType , ssize_t BufferSize>
ssize_t casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_index_
private

Definition at line 243 of file PThreadUtil.h.


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