![]() |
PIDUINO
|
Thread-safe queue implementation. More...
#include <tsqueue.h>
Public Member Functions | |
void | push (T item) |
Pushes an item into the queue. | |
T | pop () |
Pops an item from the queue. | |
bool | empty () const |
Checks if the queue is empty. | |
size_t | size () const |
Gets the size of the queue. | |
void | clear () |
Clears the queue. | |
Private Attributes | |
std::queue< T > | m_queue |
std::mutex | m_mutex |
std::condition_variable | m_cond |
Thread-safe queue implementation.
This class provides a thread-safe queue (TSQueue) for storing elements of type T. It uses a std::queue as the underlying container and synchronizes access using std::mutex and std::condition_variable to ensure safe concurrent access from multiple threads.
T | Type of elements stored in the queue. |
|
inline |
Clears the queue.
Acquires the lock and clears the queue, removing all items.
Definition at line 125 of file tsqueue.h.
References Piduino::TSQueue< T >::m_mutex, and Piduino::TSQueue< T >::m_queue.
|
inline |
Checks if the queue is empty.
Acquires the lock and checks if the queue is empty.
Definition at line 95 of file tsqueue.h.
References Piduino::TSQueue< T >::m_mutex, and Piduino::TSQueue< T >::m_queue.
|
inline |
Pops an item from the queue.
Waits until the queue is not empty, then retrieves and removes the front item.
Definition at line 69 of file tsqueue.h.
References Piduino::TSQueue< T >::m_cond, Piduino::TSQueue< T >::m_mutex, and Piduino::TSQueue< T >::m_queue.
|
inline |
Pushes an item into the queue.
Acquires the lock, adds the item to the queue, and notifies one waiting thread.
item | The item to be added to the queue. |
Definition at line 49 of file tsqueue.h.
References Piduino::TSQueue< T >::m_cond, Piduino::TSQueue< T >::m_mutex, and Piduino::TSQueue< T >::m_queue.
|
inline |
Gets the size of the queue.
Acquires the lock and returns the number of items in the queue.
Definition at line 111 of file tsqueue.h.
References Piduino::TSQueue< T >::m_mutex, and Piduino::TSQueue< T >::m_queue.
|
private |
Definition at line 39 of file tsqueue.h.
Referenced by Piduino::TSQueue< T >::pop(), and Piduino::TSQueue< T >::push().
|
mutableprivate |
Definition at line 38 of file tsqueue.h.
Referenced by Piduino::TSQueue< T >::clear(), Piduino::TSQueue< T >::empty(), Piduino::TSQueue< T >::pop(), Piduino::TSQueue< T >::push(), and Piduino::TSQueue< T >::size().
|
private |
Definition at line 37 of file tsqueue.h.
Referenced by Piduino::TSQueue< T >::clear(), Piduino::TSQueue< T >::empty(), Piduino::TSQueue< T >::pop(), Piduino::TSQueue< T >::push(), and Piduino::TSQueue< T >::size().