7#include "polymorphic_optional.hpp"
8#include "../utility/utility.hpp"
9#include "../macros.hpp"
21hi_warning_ignore_msvc(26490);
35template<
typename T, std::
size_t SlotSize>
38 static_assert(std::has_single_bit(SlotSize),
"Only power-of-two number of messages size allowed.");
39 static_assert(SlotSize < 65536);
46 constexpr static std::size_t num_slots = fifo_size / slot_size;
58 [[nodiscard]]
bool empty() const noexcept
60 return _head.load(std::memory_order::relaxed) == _tail;
70 template<
typename Func>
73 auto result = get_slot(_tail).invoke_and_reset(std::forward<Func>(func));
86 template<
typename Operation>
87 void take_all(Operation
const& operation)
noexcept
89 while (take_one(operation)) {}
99 template<
typename Message,
typename Func,
typename... Args>
109 hilet offset = _head.fetch_add(slot_size, std::memory_order::relaxed);
110 return get_slot(offset).template wait_emplace_and_invoke<Message>(std::forward<Func>(func), std::forward<Args>(args)...);
113 template<
typename Func,
typename Object>
114 hi_force_inline
auto insert_and_invoke(Func&& func, Object&&
object)
noexcept
116 return emplace_and_invoke<std::decay_t<Object>>(std::forward<Func>(func), std::forward<Object>(
object));
119 template<
typename Message,
typename... Args>
120 hi_force_inline
void emplace(Args&&...args)
noexcept
122 return emplace_and_invoke<Message>([](Message&) ->
void {}, std::forward<Args>(args)...);
125 template<
typename Object>
126 hi_force_inline
void insert(Object &&
object)
noexcept
128 return emplace<std::decay_t<Object>>(std::forward<Object>(
object));
139 hi_force_inline slot_type& get_slot(uint16_t offset)
noexcept
141 hi_axiom(offset % slot_size == 0);
143 return *std::launder(
144 std::assume_aligned<slot_size>(
reinterpret_cast<slot_type *
>(
reinterpret_cast<char *
>(
this) + offset)));
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Polymorphic optional.
Definition polymorphic_optional.hpp:41
A wait-free multiple-producer/single-consumer fifo designed for absolute performance.
Definition wfree_fifo.hpp:36
auto take_one(Func &&func) noexcept
Take one message from the fifo slot.
Definition wfree_fifo.hpp:71
void take_all(Operation const &operation) noexcept
Take all message from the queue.
Definition wfree_fifo.hpp:87
bool empty() const noexcept
Check if fifo is empty.
Definition wfree_fifo.hpp:58
hi_force_inline auto emplace_and_invoke(Func &&func, Args &&...args) noexcept
Create an message in-place on the fifo.
Definition wfree_fifo.hpp:100