|
TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
|
A thread-safe queue implementation for storing and retrieving elements of type T. More...
#include <tec_queue.hpp>
Public Member Functions | |
| SafeQueue (void) | |
| Constructs an empty thread-safe queue. | |
| ~SafeQueue (void)=default | |
| Destructor for the SafeQueue. | |
| void | enqueue (T &&t) |
| Adds an element to the back of the queue. | |
| T | dequeue (void) |
| Retrieves and removes the front element from the queue. | |
| std::size_t | size () const |
| Returns the current number of elements in the queue. | |
A thread-safe queue implementation for storing and retrieving elements of type T.
This class provides a thread-safe queue using a mutex and condition variable to ensure safe access and modification in a multi-threaded environment. It supports enqueueing, dequeueing, and size querying operations.
| T | The type of elements stored in the queue. |
|
inline |
Constructs an empty thread-safe queue.
Initializes an empty queue with a mutex and condition variable for thread-safe operations.
Destructor for the SafeQueue.
Cleans up the queue, mutex, and condition variable. No additional cleanup is required as the standard library handles resource management.
Retrieves and removes the front element from the queue.
If the queue is empty, the calling thread waits until an element becomes available. The operation is thread-safe.
Adds an element to the back of the queue.
Moves the provided element into the queue in a thread-safe manner and notifies one waiting thread that a new element is available.
| t | The element to add to the queue (moved into the queue). |
|
inline |
Returns the current number of elements in the queue.
Provides a thread-safe way to query the queue's size.