marvin 0.0.1
Pure C++ audio helper library
 
Loading...
Searching...
No Matches
marvin::containers::fifos::FIFO< QueueType, T > Class Template Referencefinal

A thread-safe, realtime-safe fifo. More...

#include <marvin_FIFO.h>

Public Member Functions

 FIFO (size_t maxSize)
 
std::optional< T > tryPop () noexcept
 
void tryPush (T &&x) noexcept
 
void emptyQueue () noexcept
 

Detailed Description

template<Type QueueType, typename T>
requires std::is_copy_constructible_v<T> && std::is_move_constructible_v<T> && std::is_default_constructible_v<T>
class marvin::containers::fifos::FIFO< QueueType, T >

A thread-safe, realtime-safe fifo.

Can be configured as either a single producer, single consumer queue (SPSC), a wrapper around cameron314's readerwriterqueue, or a multi producer, multi consumer queue (MPMC), a wrapper around cameron314's concurrentqueue.
Suitable for passing data between threads. If the queue is full, pushing will have no effect, and if the queue is empty, popping will return a std::nullopt.
T must be default-constructible, copy constructible and move constructible.
To empty the queue in a single loop:

class SomeClass {
public:
void emptyQueue() {
while(std::optional<int> current = m_fifo.tryPop()) {
std::cout << "Dequeued " << *current << "\n"; // Or do something meaningful with the data here...
}
}
private:
marvin::utils::fifos::SPSC<int> m_fifo;
};
void emptyQueue() noexcept
Definition marvin_FIFO.h:90

Constructor & Destructor Documentation

◆ FIFO()

template<Type QueueType, typename T>
marvin::containers::fifos::FIFO< QueueType, T >::FIFO ( size_t maxSize)
inlineexplicit
Parameters
maxSizeThe capacity of the fifo.

Member Function Documentation

◆ emptyQueue()

template<Type QueueType, typename T>
void marvin::containers::fifos::FIFO< QueueType, T >::emptyQueue ( )
inlinenoexcept

Removes all queued elements, discarding their values.

◆ tryPop()

template<Type QueueType, typename T>
std::optional< T > marvin::containers::fifos::FIFO< QueueType, T >::tryPop ( )
inlinenodiscardnoexcept

Tries to pop an element from the front of the queue.

Returns
std::nullopt if the queue is empty, the value at the front of the queue otherwise.

◆ tryPush()

template<Type QueueType, typename T>
void marvin::containers::fifos::FIFO< QueueType, T >::tryPush ( T && x)
inlinenoexcept

Tries to emplace an element into the back of the queue. If the queue is full, has no effect. Never allocates.

Parameters
xThe value to push into the queue.

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