MRPT
2.0.4
|
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 53 of file CThreadSafeQueue.h.
#include <mrpt/containers/CThreadSafeQueue.h>
Public Member Functions | |
CThreadSafeQueue ()=default | |
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... | |
|
default |
Default ctor.
|
inlinevirtual |
Definition at line 65 of file CThreadSafeQueue.h.
|
inline |
Clear the queue of messages, freeing memory as required.
Definition at line 67 of file CThreadSafeQueue.h.
Referenced by mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::~CThreadSafeQueue().
|
inline |
Return true if there are no messages.
Definition at line 129 of file CThreadSafeQueue.h.
|
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 90 of file CThreadSafeQueue.h.
Referenced by mrpt::hmtslam::CHMTSLAM::thread_LSLAM().
|
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 109 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 80 of file CThreadSafeQueue.h.
|
inline |
Return the number of queued messages.
Definition at line 136 of file CThreadSafeQueue.h.
|
mutableprotected |
The critical section.
Definition at line 60 of file CThreadSafeQueue.h.
Referenced by mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::clear(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::empty(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::get(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::get_lastest_purge_old(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::push(), and mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::size().
|
protected |
The queue of messages.
Memory is freed at destructor or by clients gathering messages.
Definition at line 58 of file CThreadSafeQueue.h.
Referenced by mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::clear(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::empty(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::get(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::get_lastest_purge_old(), mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::push(), and mrpt::containers::CThreadSafeQueue< mrpt::serialization::CMessage >::size().
Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020 |