Motion Master
Loading...
Searching...
No Matches
Public Member Functions | List of all members
mm::core::util::ThreadSafeQueue< T > Class Template Reference

A simple thread-safe FIFO queue. More...

#include <util.h>

Public Member Functions

 ThreadSafeQueue ()=default
 Construct a new empty ThreadSafeQueue. More...
 
 ThreadSafeQueue (const ThreadSafeQueue &)=delete
 Deleted copy constructor. More...
 
ThreadSafeQueueoperator= (const ThreadSafeQueue &)=delete
 Deleted copy assignment operator. More...
 
void push (T value)
 Push a new value into the queue. More...
 
std::optional< T > try_pop ()
 Try to pop a value from the queue without blocking. More...
 
wait_and_pop ()
 Wait for an item to be available and pop it. More...
 
bool empty () const
 Check whether the queue is empty. More...
 
size_t size () const
 Get the current number of items in the queue. More...
 

Detailed Description

template<typename T>
class mm::core::util::ThreadSafeQueue< T >

A simple thread-safe FIFO queue.

Provides push, blocking pop, and non-blocking pop operations with thread safety using a mutex and condition variable.

Template Parameters
TType of elements stored in the queue.

Constructor & Destructor Documentation

◆ ThreadSafeQueue() [1/2]

template<typename T >
mm::core::util::ThreadSafeQueue< T >::ThreadSafeQueue ( )
default

Construct a new empty ThreadSafeQueue.

◆ ThreadSafeQueue() [2/2]

template<typename T >
mm::core::util::ThreadSafeQueue< T >::ThreadSafeQueue ( const ThreadSafeQueue< T > &  )
delete

Deleted copy constructor.

Member Function Documentation

◆ empty()

template<typename T >
bool mm::core::util::ThreadSafeQueue< T >::empty ( ) const
inline

Check whether the queue is empty.

Returns
true if the queue is empty, false otherwise.

◆ operator=()

template<typename T >
ThreadSafeQueue & mm::core::util::ThreadSafeQueue< T >::operator= ( const ThreadSafeQueue< T > &  )
delete

Deleted copy assignment operator.

◆ push()

template<typename T >
void mm::core::util::ThreadSafeQueue< T >::push ( value)
inline

Push a new value into the queue.

Parameters
valueValue to push.

◆ size()

template<typename T >
size_t mm::core::util::ThreadSafeQueue< T >::size ( ) const
inline

Get the current number of items in the queue.

Note: size may change immediately after this call in concurrent use.

Returns
The number of items currently in the queue.

◆ try_pop()

template<typename T >
std::optional< T > mm::core::util::ThreadSafeQueue< T >::try_pop ( )
inline

Try to pop a value from the queue without blocking.

Returns
An optional containing the popped value if available, or std::nullopt if the queue was empty.

◆ wait_and_pop()

template<typename T >
T mm::core::util::ThreadSafeQueue< T >::wait_and_pop ( )
inline

Wait for an item to be available and pop it.

Blocks until an item is available.

Returns
The popped value.

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