HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes
v1::wfree_fifo< T, SlotSize > Class Template Reference

#include <hikogui/container/wfree_fifo.hpp>

Public Types

using value_type = T
 
using slot_type = polymorphic_optional<value_type, SlotSize, SlotSize>
 

Public Member Functions

 wfree_fifo (wfree_fifo const &)=delete
 
 wfree_fifo (wfree_fifo &&)=delete
 
wfree_fifooperator= (wfree_fifo const &)=delete
 
wfree_fifooperator= (wfree_fifo &&)=delete
 
bool empty () const noexcept
 Check if fifo is empty.
 
template<typename Func >
auto take_one (Func &&func) noexcept
 Take one message from the fifo slot.
 
template<typename Operation >
void take_all (Operation const &operation) noexcept
 Take all message from the queue.
 
template<typename Message , typename Func , typename... Args>
hi_force_inline auto emplace_and_invoke (Func &&func, Args &&...args) noexcept
 Create an message in-place on the fifo.
 
template<typename Func , typename Object >
hi_force_inline auto insert_and_invoke (Func &&func, Object &&object) noexcept
 
template<typename Message , typename... Args>
hi_force_inline void emplace (Args &&...args) noexcept
 
template<typename Object >
hi_force_inline void insert (Object &&object) noexcept
 

Static Public Attributes

static constexpr std::size_t fifo_size = 65536
 
static constexpr std::size_t slot_size = SlotSize
 
static constexpr std::size_t num_slots = fifo_size / slot_size
 

Detailed Description

template<typename T, std::size_t SlotSize>
class v1::wfree_fifo< T, SlotSize >

A wait-free multiple-producer/single-consumer fifo designed for absolute performance.

Because of performance reasons the ring-buffer is 64kByte. Each slot in the ring buffer consists of a pointer and a byte buffer for storage.

The number of slots in the ring-buffer is dictated by the size of each slot and the ring-buffer size.

Template Parameters
TBase class of the value type stored in the ring buffer.
SlotSizeSize of each slot, must be power-of-two.

Member Function Documentation

◆ emplace_and_invoke()

template<typename T , std::size_t SlotSize>
template<typename Message , typename Func , typename... Args>
hi_force_inline auto v1::wfree_fifo< T, SlotSize >::emplace_and_invoke ( Func && func,
Args &&... args )
inlinenoexcept

Create an message in-place on the fifo.

Template Parameters
MessageThe message type derived from value_type to be stored in a free slot.
Parameters
funcThe function to invoke on the message created on the fifo.
argsThe arguments passed to the constructor of Message.
Returns
A reference to the emplaced message.

◆ empty()

template<typename T , std::size_t SlotSize>
bool v1::wfree_fifo< T, SlotSize >::empty ( ) const
inlinenoexcept

Check if fifo is empty.

Note
Must be called on the reader-thread.

◆ take_all()

template<typename T , std::size_t SlotSize>
template<typename Operation >
void v1::wfree_fifo< T, SlotSize >::take_all ( Operation const & operation)
inlinenoexcept

Take all message from the queue.

Reads each message from the ring buffer and passes it to a call of operation. If no message are available this function returns without calling operation.

Parameters
operationA void(value_type const &) which is called when a message is available.

◆ take_one()

template<typename T , std::size_t SlotSize>
template<typename Func >
auto v1::wfree_fifo< T, SlotSize >::take_one ( Func && func)
inlinenoexcept

Take one message from the fifo slot.

Reads one message from the ring buffer and passes it to a call of operation. If no message is available this function returns without calling operation.

Parameters
funcThe function to call with the value as argument if it exists.
Returns
If empty/false the this was empty, otherwise it contains the return value of the function if any.

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