A thread-safe template queue for object passing between threads; for a template argument of T, the objects being passed in the queue are "T*".
Usage example:
Note that only dynamically allocated objects can be inserted with push() and that freeing that memory if responsibility of the receiver of this queue as it receives objects with get(). However, elements still in the queue upon destruction will be deleted automatically.
Definition at line 74 of file CThreadSafeQueue.h.
#include <mrpt/utils/CThreadSafeQueue.h>

Public Member Functions | |
| CThreadSafeQueue () | |
| Default ctor. | |
| virtual | ~CThreadSafeQueue () |
| void | clear () |
| Clear the queue of messages, freeing memory as required. | |
| void | push (T *msg) |
| Insert a new message in the queue - The object must be created with "new", and do not delete is after calling this, it must be deleted later. | |
| T * | get () |
| Retrieve the next message in the queue, or NULL if there is no message. | |
| T * | get_lastest_purge_old () |
| Skip all old messages in the queue and directly return the last one (the most recent, at the bottom of the queue), or NULL if there is no message. | |
| bool | empty () const |
| Return true if there are no messages. | |
| size_t | size () const |
| Return the number of queued messages. | |
Protected Attributes | |
| std::queue< T * > | m_msgs |
| The queue of messages. Memory is freed at destructor or by clients gathering messages. | |
| mrpt::synch::CCriticalSection | m_csQueue |
| The critical section. | |
|
inline |
Default ctor.
Definition at line 81 of file CThreadSafeQueue.h.
|
inlinevirtual |
Definition at line 83 of file CThreadSafeQueue.h.
|
inline |
Clear the queue of messages, freeing memory as required.
Definition at line 89 of file CThreadSafeQueue.h.
Referenced by mrpt::utils::CThreadSafeQueue< CMessage >::~CThreadSafeQueue().
|
inline |
Return true if there are no messages.
Definition at line 145 of file CThreadSafeQueue.h.
|
inline |
Retrieve the next message in the queue, or NULL if there is no message.
The user MUST call "delete" with the returned object after use.
Definition at line 110 of file CThreadSafeQueue.h.
|
inline |
Skip all old messages in the queue and directly return the last one (the most recent, at the bottom of the queue), or NULL if there is no message.
Definition at line 127 of file CThreadSafeQueue.h.
|
inline |
Insert a new message in the queue - The object must be created with "new", and do not delete is after calling this, it must be deleted later.
Definition at line 101 of file CThreadSafeQueue.h.
|
inline |
Return the number of queued messages.
Definition at line 152 of file CThreadSafeQueue.h.
|
protected |
The critical section.
Definition at line 78 of file CThreadSafeQueue.h.
Referenced by mrpt::utils::CThreadSafeQueue< CMessage >::clear(), mrpt::utils::CThreadSafeQueue< CMessage >::empty(), mrpt::utils::CThreadSafeQueue< CMessage >::get(), mrpt::utils::CThreadSafeQueue< CMessage >::get_lastest_purge_old(), mrpt::utils::CThreadSafeQueue< CMessage >::push(), and mrpt::utils::CThreadSafeQueue< CMessage >::size().
|
protected |
The queue of messages. Memory is freed at destructor or by clients gathering messages.
Definition at line 77 of file CThreadSafeQueue.h.
Referenced by mrpt::utils::CThreadSafeQueue< CMessage >::clear(), mrpt::utils::CThreadSafeQueue< CMessage >::empty(), mrpt::utils::CThreadSafeQueue< CMessage >::get(), mrpt::utils::CThreadSafeQueue< CMessage >::get_lastest_purge_old(), mrpt::utils::CThreadSafeQueue< CMessage >::push(), and mrpt::utils::CThreadSafeQueue< CMessage >::size().
| Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013 |