casa
5.7.0-16
|
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_ |
implementation of producer consumer model
Definition at line 104 of file PThreadUtil.h.
typedef ProducerConsumerModelContext<DataType, BufferSize> casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::_Context |
Definition at line 106 of file PThreadUtil.h.
|
inline |
constructor
std::cout << "end_of_production = " << end_of_production_ << std::endl;
Definition at line 161 of file PThreadUtil.h.
|
inline |
destructor
Definition at line 169 of file PThreadUtil.h.
|
inlineprivate |
Definition at line 213 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().
|
inlineprivate |
Definition at line 209 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
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_.
|
inlinestatic |
consumption function return false if no more products available otherwise return true
wait until something is produced
send a signal to consumer since there are available slot in buffer
Definition at line 132 of file PThreadUtil.h.
References casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::buffer_is_empty(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_next(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_wait(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::end_of_production_, casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::lock(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::pop_product(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_signal(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::unlock().
|
inlineprivate |
Definition at line 223 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().
|
inlineprivate |
Definition at line 205 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
inlineprivate |
Definition at line 201 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().
|
inlineprivate |
Definition at line 181 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::locked_print(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
inlinestatic |
utility
Definition at line 174 of file PThreadUtil.h.
References casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::lock(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::unlock().
|
inlineprivate |
Definition at line 233 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().
|
inlinestatic |
production function
wait until buffer becomes available for production
send a signal to consumer since something is produced
Definition at line 109 of file PThreadUtil.h.
References casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::buffer_is_full(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consumer_signal(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::lock(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_next(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::producer_wait(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::push_product(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::unlock().
|
inlineprivate |
Definition at line 217 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
inlineprivate |
Definition at line 197 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume().
|
inlineprivate |
Definition at line 193 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
inlineprivate |
Definition at line 229 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
inlineprivate |
Definition at line 189 of file PThreadUtil.h.
|
inlineprivate |
Definition at line 185 of file PThreadUtil.h.
Referenced by casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::consume(), casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::locked_print(), and casa::sdfiller::ProducerConsumerModelContext< DataType, BufferSize >::produce().
|
private |
Definition at line 241 of file PThreadUtil.h.
|
private |
Definition at line 246 of file PThreadUtil.h.
|
private |
Definition at line 244 of file PThreadUtil.h.
|
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().
|
private |
Definition at line 245 of file PThreadUtil.h.
|
private |
Definition at line 242 of file PThreadUtil.h.
|
private |
Definition at line 247 of file PThreadUtil.h.
|
private |
Definition at line 243 of file PThreadUtil.h.