dlvhex  2.5.0
dlvhex::ConcurrentMessageQueueOwning< MessageBase > Class Template Reference

Message queue for inter-thread communication. More...

#include <include/dlvhex2/ConcurrentMessageQueueOwning.h>

Collaboration diagram for dlvhex::ConcurrentMessageQueueOwning< MessageBase >:

Public Member Functions

 ConcurrentMessageQueueOwning ()
 Default constructor, capacity is one.
 ConcurrentMessageQueueOwning (std::size_t capacity)
 Initialize with capacity, if capacity is 0, we force it to be 1.
 ConcurrentMessageQueueOwning (const ConcurrentMessageQueueOwning< MessageBase > &q)
 Copy-constructor, just take capacity but not content.
virtual ~ConcurrentMessageQueueOwning ()
 Destructor.
void flush ()
 Pop all element from the queue.
bool empty () const
 Clear queue.
bool size () const
 Return size of the queue.
void send (MessagePtr m, unsigned int prio)
 Send message.
bool try_send (MessagePtr m, unsigned int prio)
 Try to send a message.
bool timed_send (MessagePtr m, unsigned int prio, const boost::posix_time::time_duration &t)
 Try to send a message respecting a timeout.
void receive (MessagePtr &m, unsigned int &prio)
 Receive a message.
bool try_receive (MessagePtr &m, unsigned int prio)
 Try to receive a message.
bool timed_receive (MessagePtr &m, unsigned int &prio, const boost::posix_time::time_duration &t)
 Try to receive a message respecting a timeout.

Private Types

typedef boost::shared_ptr
< MessageBase > 
MessagePtr

Private Member Functions

void notifyConsumer ()
 Notifier of model consumer.
void notifyProducer ()
 Notifier of model produces.
void waitOnCapacity (boost::mutex::scoped_lock &lock)
 Wait until free space is available in the queue.
void waitOnEmpty (boost::mutex::scoped_lock &lock)
 Wait until the queue is empty.
bool waitOnTimedCapacity (boost::mutex::scoped_lock &lock, const boost::posix_time::time_duration &t)
 Wait until free space is available in the queue respecting a timeout.
bool waitOnTimedEmpty (boost::mutex::scoped_lock &lock, const boost::posix_time::time_duration &t)
 Wait until queue is empty respecting a timeout.
void pushMessage (MessagePtr m)
 Add a message.
void popMessage (MessagePtr &m)
 Retrieve and remove a message.

Private Attributes

std::queue< MessagePtrq
 Holds data of message queue.
const std::size_t n
 Capacity of message queue.
std::size_t enq
 Enqueuing counter.
std::size_t deq
 Dequeuing counter.
boost::mutex mtx
 A mutex lock and the associated condition variable.
boost::condition_variable cnd
 Condition for multithreading access.

Detailed Description

template<class MessageBase>
class dlvhex::ConcurrentMessageQueueOwning< MessageBase >

Message queue for inter-thread communication.

Modelled after boost::interprocess::message_queue.

Definition at line 48 of file ConcurrentMessageQueueOwning.h.


Member Typedef Documentation

template<class MessageBase>
typedef boost::shared_ptr<MessageBase> dlvhex::ConcurrentMessageQueueOwning< MessageBase >::MessagePtr [private]

Definition at line 51 of file ConcurrentMessageQueueOwning.h.


Constructor & Destructor Documentation

template<class MessageBase>
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning ( ) [inline]

Default constructor, capacity is one.

Definition at line 169 of file ConcurrentMessageQueueOwning.h.

template<class MessageBase>
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning ( std::size_t  capacity) [inline]

Initialize with capacity, if capacity is 0, we force it to be 1.

Parameters:
capacitythe capacity of this message queue.

Definition at line 178 of file ConcurrentMessageQueueOwning.h.

template<class MessageBase>
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning ( const ConcurrentMessageQueueOwning< MessageBase > &  q) [inline]

Copy-constructor, just take capacity but not content.

Parameters:
qSecond ConcurrentMessageQueueOwning.

Definition at line 184 of file ConcurrentMessageQueueOwning.h.

template<class MessageBase>
virtual dlvhex::ConcurrentMessageQueueOwning< MessageBase >::~ConcurrentMessageQueueOwning ( ) [inline, virtual]

Member Function Documentation

template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::empty ( ) const [inline]
template<class MessageBase>
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::receive ( MessagePtr m,
unsigned int &  prio 
) [inline]
template<class MessageBase>
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::send ( MessagePtr  m,
unsigned int  prio 
) [inline]
template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::size ( ) const [inline]

Return size of the queue.

Returns:
Size.

Definition at line 217 of file ConcurrentMessageQueueOwning.h.

References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n.

template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_receive ( MessagePtr m,
unsigned int &  prio,
const boost::posix_time::time_duration &  t 
) [inline]

Try to receive a message respecting a timeout.

Parameters:
mOutput message.
prioUnused.
Returns:
t Timeout.
True if succeeded.

Definition at line 299 of file ConcurrentMessageQueueOwning.h.

References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().

template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_send ( MessagePtr  m,
unsigned int  prio,
const boost::posix_time::time_duration &  t 
) [inline]

Try to send a message respecting a timeout.

Parameters:
mMessage.
prioUnused.
tTimeout.
Returns:
True if succeeded.

Definition at line 255 of file ConcurrentMessageQueueOwning.h.

References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity().

template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive ( MessagePtr m,
unsigned int  prio 
) [inline]
template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity ( boost::mutex::scoped_lock &  lock,
const boost::posix_time::time_duration &  t 
) [inline, private]
template<class MessageBase>
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty ( boost::mutex::scoped_lock &  lock,
const boost::posix_time::time_duration &  t 
) [inline, private]

Field Documentation


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