HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions
v1::function_fifo< Proto, SlotSize > Class Template Reference

#include <hikogui/container/function_fifo.hpp>

Public Member Functions

 function_fifo (function_fifo const &)=delete
 
 function_fifo (function_fifo &&)=delete
 
function_fifooperator= (function_fifo const &)=delete
 
function_fifooperator= (function_fifo &&)=delete
 
bool empty () const noexcept
 Check if there are not functions added to the fifo.
 
template<typename... Args>
auto run_one (Args const &...args) noexcept
 Run one of the function that was posted or send.
 
void run_all () noexcept
 Run all the functions posted or send on the fifo.
 
template<typename Func >
void add_function (Func &&func) noexcept
 Asynchronously post a functor to the fifo to be executed later.
 
template<typename Func , typename... Args>
requires (std::is_invocable_v<std::decay_t<Func>, std::decay_t<Args>...>)
auto add_async_function (Func &&func, Args &&...args) noexcept
 Asynchronously send a functor to the fifo to be executed later.
 

Detailed Description

template<typename Proto = void(), std::size_t SlotSize = 64>
class v1::function_fifo< Proto, SlotSize >

A fifo (First-in, Firts-out) for asynchronous calls.

This fifo is used to handle asynchronous calls from an event-loop.

Template Parameters
ProtoThe std::function prototype.
SlotSizeThe size in bytes of each slot. This determines the maximum number of functions that can be stored on the fifo and if functions can be completely stored on the fifo or are allocated on the heap.

Member Function Documentation

◆ add_async_function()

template<typename Proto = void(), std::size_t SlotSize = 64>
template<typename Func , typename... Args>
requires (std::is_invocable_v<std::decay_t<Func>, std::decay_t<Args>...>)
auto v1::function_fifo< Proto, SlotSize >::add_async_function ( Func && func,
Args &&... args )
inlinenoexcept

Asynchronously send a functor to the fifo to be executed later.

The function object and arguments are stored within the fifo and does not need allocation. However the std::promise object will allocate the return object on the heap as it must be shared with std::future.

Parameters
funcA function object.
argsThe arguments to pass to the function when called.
Returns
A std::future with the result of func. The result type may be void.

◆ add_function()

template<typename Proto = void(), std::size_t SlotSize = 64>
template<typename Func >
void v1::function_fifo< Proto, SlotSize >::add_function ( Func && func)
inlinenoexcept

Asynchronously post a functor to the fifo to be executed later.

The function object and arguments are stored within the fifo and does not need allocation.

Note
wait-free if the function object and arguments fit in the message slot of the fifo.
Parameters
funcA function object.

◆ empty()

template<typename Proto = void(), std::size_t SlotSize = 64>
bool v1::function_fifo< Proto, SlotSize >::empty ( ) const
inlinenoexcept

Check if there are not functions added to the fifo.

◆ run_all()

template<typename Proto = void(), std::size_t SlotSize = 64>
void v1::function_fifo< Proto, SlotSize >::run_all ( )
inlinenoexcept

Run all the functions posted or send on the fifo.

This function calls run_one() until the fifo is empty.

◆ run_one()

template<typename Proto = void(), std::size_t SlotSize = 64>
template<typename... Args>
auto v1::function_fifo< Proto, SlotSize >::run_one ( Args const &... args)
inlinenoexcept

Run one of the function that was posted or send.

Return values
trueOne async function has been taken from the fifo and run.
falseThe fifo was empty.

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