Lightweight 0.20251202.0
Loading...
Searching...
No Matches
Lightweight::ThreadSafeQueue< T > Class Template Reference

#include <ThreadSafeQueue.hpp>

Public Member Functions

void Push (T item)
 
bool WaitAndPop (T &item)
 
void MarkFinished ()
 
bool Empty () const
 
size_t Size () const
 

Detailed Description

template<typename T>
class Lightweight::ThreadSafeQueue< T >

Thread-safe queue with blocking wait semantics.

This queue allows multiple producer and consumer threads to safely enqueue and dequeue items. Consumers block on WaitAndPop until an item is available or the queue is marked as finished.

Template Parameters
TThe type of items stored in the queue.

Definition at line 20 of file ThreadSafeQueue.hpp.

Member Function Documentation

◆ Push()

template<typename T >
void Lightweight::ThreadSafeQueue< T >::Push ( item)
inline

Pushes an item onto the queue and notifies one waiting consumer.

Parameters
itemThe item to push onto the queue.

Definition at line 26 of file ThreadSafeQueue.hpp.

◆ WaitAndPop()

template<typename T >
bool Lightweight::ThreadSafeQueue< T >::WaitAndPop ( T &  item)
inline

Blocks until an item is available or the queue is finished.

This method will block the calling thread until either:

  • An item becomes available in the queue, or
  • The queue has been marked as finished and is empty.
Parameters
itemOutput parameter to receive the popped item.
Returns
true if an item was successfully popped, false if the queue is finished and empty.

Definition at line 43 of file ThreadSafeQueue.hpp.

◆ MarkFinished()

template<typename T >
void Lightweight::ThreadSafeQueue< T >::MarkFinished ( )
inline

Signals that no more items will be added.

After this call, WaitAndPop will return false once the queue is empty. All waiting consumers will be notified.

Definition at line 58 of file ThreadSafeQueue.hpp.

◆ Empty()

template<typename T >
bool Lightweight::ThreadSafeQueue< T >::Empty ( ) const
inline

Checks if the queue is empty.

Returns
true if the queue is currently empty.

Definition at line 70 of file ThreadSafeQueue.hpp.

◆ Size()

template<typename T >
size_t Lightweight::ThreadSafeQueue< T >::Size ( ) const
inline

Returns the current size of the queue.

Returns
The number of items currently in the queue.

Definition at line 79 of file ThreadSafeQueue.hpp.


The documentation for this class was generated from the following file: