dlvhex
2.5.0
|
Message queue for inter-thread communication. More...
#include <include/dlvhex2/ConcurrentMessageQueueOwning.h>
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< MessagePtr > | q |
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. |
Message queue for inter-thread communication.
Modelled after boost::interprocess::message_queue.
Definition at line 48 of file ConcurrentMessageQueueOwning.h.
typedef boost::shared_ptr<MessageBase> dlvhex::ConcurrentMessageQueueOwning< MessageBase >::MessagePtr [private] |
Definition at line 51 of file ConcurrentMessageQueueOwning.h.
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning | ( | ) | [inline] |
Default constructor, capacity is one.
Definition at line 169 of file ConcurrentMessageQueueOwning.h.
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning | ( | std::size_t | capacity | ) | [inline] |
Initialize with capacity, if capacity is 0, we force it to be 1.
capacity | the capacity of this message queue. |
Definition at line 178 of file ConcurrentMessageQueueOwning.h.
dlvhex::ConcurrentMessageQueueOwning< MessageBase >::ConcurrentMessageQueueOwning | ( | const ConcurrentMessageQueueOwning< MessageBase > & | q | ) | [inline] |
Copy-constructor, just take capacity but not content.
q | Second ConcurrentMessageQueueOwning. |
Definition at line 184 of file ConcurrentMessageQueueOwning.h.
virtual dlvhex::ConcurrentMessageQueueOwning< MessageBase >::~ConcurrentMessageQueueOwning | ( | ) | [inline, virtual] |
Destructor.
Definition at line 190 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::flush().
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::empty | ( | ) | const [inline] |
Clear queue.
Definition at line 208 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::flush | ( | ) | [inline] |
Pop all element from the queue.
Definition at line 195 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::~ConcurrentMessageQueueOwning().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer | ( | ) | [inline, private] |
Notifier of model consumer.
Definition at line 69 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::deq.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer | ( | ) | [inline, private] |
Notifier of model produces.
Definition at line 78 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::enq.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::flush(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage | ( | MessagePtr & | m | ) | [inline, private] |
Retrieve and remove a message.
m | Retrieved message. |
Definition at line 161 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::receive(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_receive(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage | ( | MessagePtr | m | ) | [inline, private] |
Add a message.
m | Message to add. |
Definition at line 154 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_send(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::receive | ( | MessagePtr & | m, |
unsigned int & | prio | ||
) | [inline] |
Receive a message.
m | Output message. |
prio | Unused. |
Definition at line 270 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::send | ( | MessagePtr | m, |
unsigned int | prio | ||
) | [inline] |
Send message.
m | Message. |
prio | Unused. |
Definition at line 226 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity().
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::size | ( | ) | const [inline] |
Return size of the queue.
Definition at line 217 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n.
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.
m | Output message. |
prio | Unused. |
Definition at line 299 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().
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.
m | Message. |
prio | Unused. |
t | Timeout. |
Definition at line 255 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity().
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive | ( | MessagePtr & | m, |
unsigned int | prio | ||
) | [inline] |
Try to receive a message.
m | Output message. |
prio | Unused. |
Definition at line 281 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send | ( | MessagePtr | m, |
unsigned int | prio | ||
) | [inline] |
Try to send a message.
m | Message. |
prio | Unused. |
Definition at line 237 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity | ( | boost::mutex::scoped_lock & | lock | ) | [inline, private] |
Wait until free space is available in the queue.
Definition at line 87 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::enq, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::send().
void dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty | ( | boost::mutex::scoped_lock & | lock | ) | [inline, private] |
Wait until the queue is empty.
Definition at line 100 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::deq, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::receive().
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity | ( | boost::mutex::scoped_lock & | lock, |
const boost::posix_time::time_duration & | t | ||
) | [inline, private] |
Wait until free space is available in the queue respecting a timeout.
lock | Mutex. |
t | Timeout |
Definition at line 116 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::enq, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_send().
bool dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty | ( | boost::mutex::scoped_lock & | lock, |
const boost::posix_time::time_duration & | t | ||
) | [inline, private] |
Wait until queue is empty respecting a timeout.
lock | Mutex. |
t | Timeout |
Definition at line 136 of file ConcurrentMessageQueueOwning.h.
References dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::deq, dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_receive().
boost::condition_variable dlvhex::ConcurrentMessageQueueOwning< MessageBase >::cnd [private] |
Condition for multithreading access.
Definition at line 65 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().
std::size_t dlvhex::ConcurrentMessageQueueOwning< MessageBase >::deq [private] |
Dequeuing counter.
Definition at line 60 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyConsumer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().
std::size_t dlvhex::ConcurrentMessageQueueOwning< MessageBase >::enq [private] |
Enqueuing counter.
Definition at line 58 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::notifyProducer(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity().
boost::mutex dlvhex::ConcurrentMessageQueueOwning< MessageBase >::mtx [mutable, private] |
A mutex lock and the associated condition variable.
Definition at line 63 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::empty(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::flush(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::receive(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_receive(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::timed_send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send().
const std::size_t dlvhex::ConcurrentMessageQueueOwning< MessageBase >::n [private] |
Capacity of message queue.
Definition at line 56 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::size(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity().
std::queue<MessagePtr> dlvhex::ConcurrentMessageQueueOwning< MessageBase >::q [private] |
Holds data of message queue.
Definition at line 54 of file ConcurrentMessageQueueOwning.h.
Referenced by dlvhex::ConcurrentMessageQueueOwning< MessageBase >::empty(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::flush(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::popMessage(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::pushMessage(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_receive(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::try_send(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnCapacity(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnEmpty(), dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedCapacity(), and dlvhex::ConcurrentMessageQueueOwning< MessageBase >::waitOnTimedEmpty().