Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
lampda::utils::ThreadSafeQueue< T, N > Class Template Reference

Fixed capacity FIFO queue, guarded by a mutex. Push and pop can be called from any thread, but not from an interrupt. The lock is only held while copying an item, never while the caller handles it. More...

#include <thread_safe_queue.h>

Public Member Functions

 ThreadSafeQueue (const ThreadSafeQueue &)=delete
 
ThreadSafeQueue & operator= (const ThreadSafeQueue &)=delete
 
bool push (const T &item)
 Push an item at the end of the queue.
 
etl::optional< T > pop ()
 Pop the oldest item.
 
size_t size ()
 Return the number of stored items.
 
void clear ()
 Drop all stored items.
 

Static Public Member Functions

static constexpr size_t capacity ()
 Maximum number of stored items.
 

Detailed Description

template<typename T, size_t N>
class lampda::utils::ThreadSafeQueue< T, N >

Fixed capacity FIFO queue, guarded by a mutex. Push and pop can be called from any thread, but not from an interrupt. The lock is only held while copying an item, never while the caller handles it.

Member Function Documentation

◆ pop()

template<typename T , size_t N>
etl::optional< T > lampda::utils::ThreadSafeQueue< T, N >::pop ( )
inline

Pop the oldest item.

Returns
The popped item, or nothing if the queue is empty

◆ push()

template<typename T , size_t N>
bool lampda::utils::ThreadSafeQueue< T, N >::push ( const T &  item)
inline

Push an item at the end of the queue.

Returns
false if the queue is full and the item was dropped

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