General purpose message queue for inter-thread communication.
More...
#include <MessageQueue.h>
|
| MessageQueueT (std::size_t max_capacity=std::numeric_limits< std::size_t >::max()) |
| Constructor. More...
|
|
std::size_t | pop (M &dst_message, bool block) |
| Pops one message from the queue. More...
|
|
std::size_t | push (const M &message) |
| Pushes one message into the queue. More...
|
|
void | cancel () |
| Cancel the queue functionality indefinitely releasing any blocked thread. More...
|
|
bool | is_cancelled () const |
| Returns true if the queue have been cancelled. More...
|
|
std::size_t | size () const |
| Returns the number of messages contained inside the queue. More...
|
|
template<typename M>
class MessageQueueT< M >
General purpose message queue for inter-thread communication.
This template class uses compile-time polymorphism to allow message-driven communication and synchronization between two or more threads.
The implementation of this template is based on IMessageQueue class.
- Note
- Only one method of this class can (optionally) block the calling thread: IMessageQueue::pop.
- This class is 100% thread safe.
Constructor.
- Parameters
-
max_capacity | Maximum number of messages that can be queued at the same time. By default this limit is relaxed as much as possible. |
Cancel the queue functionality indefinitely releasing any blocked thread.
The cancelled status is not reversible and is meant mainly as an action to be performed before the queue destruction.
- Note
- Doesn't wait for the peer threads to be released, just broadcast a signal to them.
Returns true if the queue have been cancelled.
template<typename M >
std::size_t MessageQueueT< M >::pop |
( |
M & |
dst_message, |
|
|
bool |
block |
|
) |
| |
|
inline |
Pops one message from the queue.
- Parameters
-
[out] | dst_message | A reference to a message object meant to be set with the extracted message only in case of success. |
| block | If set to true the method blocks the current thread indefinitely until a new message is pushed into the queue by another thread or until the queue is not cancelled. |
- Returns
- On failure, zero (parameter message is not touched in that case).
- On success, the number of messages contained by the queue before the extraction that is at least one.
- Precondition
- The queue have not been cancelled.
Pushes one message into the queue.
- Parameters
-
message | The message to be inserted. |
- Returns
- On failure, zero. This may happen if the maximum allowed capacity for the queue have been reached.
- On success, the number of messages contained by the queue after the insertion that is at least one.
- Precondition
- The queue have not been cancelled.
Returns the number of messages contained inside the queue.
The documentation for this class was generated from the following file: