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 59 of file CThreadSafeQueue.h.
#include <mrpt/utils/CThreadSafeQueue.h>
Public Member Functions | |
CThreadSafeQueue () | |
Default ctor. More... | |
virtual | ~CThreadSafeQueue () |
void | clear () |
Clear the queue of messages, freeing memory as required. More... | |
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. More... | |
T * | get () |
Retrieve the next message in the queue, or nullptr if there is no message. More... | |
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 nullptr if there is no message. More... | |
bool | empty () const |
Return true if there are no messages. More... | |
size_t | size () const |
Return the number of queued messages. More... | |
Protected Attributes | |
std::queue< T * > | m_msgs |
The queue of messages. More... | |
std::mutex | m_csQueue |
The critical section. More... | |
|
inline |
Default ctor.
Definition at line 70 of file CThreadSafeQueue.h.
|
inlinevirtual |
Definition at line 71 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::clear().
|
inline |
Clear the queue of messages, freeing memory as required.
Definition at line 73 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
Referenced by mrpt::utils::CThreadSafeQueue< T >::~CThreadSafeQueue().
|
inline |
Return true if there are no messages.
Definition at line 135 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
|
inline |
Retrieve the next message in the queue, or nullptr if there is no message.
The user MUST call "delete" with the returned object after use.
Definition at line 96 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
|
inline |
Skip all old messages in the queue and directly return the last one (the most recent, at the bottom of the queue), or nullptr if there is no message.
Definition at line 115 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
|
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 86 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
|
inline |
Return the number of queued messages.
Definition at line 142 of file CThreadSafeQueue.h.
References mrpt::utils::CThreadSafeQueue< T >::m_csQueue, and mrpt::utils::CThreadSafeQueue< T >::m_msgs.
|
mutableprotected |
The critical section.
Definition at line 66 of file CThreadSafeQueue.h.
Referenced by mrpt::utils::CThreadSafeQueue< T >::clear(), mrpt::utils::CThreadSafeQueue< T >::empty(), mrpt::utils::CThreadSafeQueue< T >::get(), mrpt::utils::CThreadSafeQueue< T >::get_lastest_purge_old(), mrpt::utils::CThreadSafeQueue< T >::push(), and mrpt::utils::CThreadSafeQueue< T >::size().
|
protected |
The queue of messages.
Memory is freed at destructor or by clients gathering messages.
Definition at line 64 of file CThreadSafeQueue.h.
Referenced by mrpt::utils::CThreadSafeQueue< T >::clear(), mrpt::utils::CThreadSafeQueue< T >::empty(), mrpt::utils::CThreadSafeQueue< T >::get(), mrpt::utils::CThreadSafeQueue< T >::get_lastest_purge_old(), mrpt::utils::CThreadSafeQueue< T >::push(), and mrpt::utils::CThreadSafeQueue< T >::size().
Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019 |