7#include "utility/module.hpp"
9#include "polymorphic_optional.hpp"
19hi_warning_ignore_msvc(26490);
21namespace hi::inline
v1 {
33template<
typename T, std::
size_t SlotSize>
36 static_assert(std::has_single_bit(SlotSize),
"Only power-of-two number of messages size allowed.");
37 static_assert(SlotSize < 65536);
44 static constexpr std::size_t num_slots = fifo_size / slot_size;
56 [[nodiscard]]
bool empty() const noexcept
58 return _head.load(std::memory_order::relaxed) == _tail;
68 template<
typename Func>
71 auto result = get_slot(_tail).invoke_and_reset(std::forward<Func>(func));
84 template<
typename Operation>
85 void take_all(Operation
const& operation)
noexcept
87 while (take_one(operation)) {}
97 template<
typename Message,
typename Func,
typename... Args>
107 hilet offset = _head.fetch_add(slot_size, std::memory_order::relaxed);
108 return get_slot(offset).template wait_emplace_and_invoke<Message>(std::forward<Func>(func), std::forward<Args>(args)...);
111 template<
typename Func,
typename Object>
112 hi_force_inline
auto insert_and_invoke(Func&& func, Object&&
object)
noexcept
114 return emplace_and_invoke<std::decay_t<Object>>(std::forward<Func>(func), std::forward<Object>(
object));
117 template<
typename Message,
typename... Args>
118 hi_force_inline
void emplace(Args&&...args)
noexcept
120 return emplace_and_invoke<Message>([](Message&) ->
void {}, std::forward<Args>(args)...);
123 template<
typename Object>
124 hi_force_inline
void insert(Object &&
object)
noexcept
126 return emplace<std::decay_t<Object>>(std::forward<Object>(
object));
137 hi_force_inline slot_type& get_slot(uint16_t offset)
noexcept
141 return *std::launder(
142 std::assume_aligned<slot_size>(
reinterpret_cast<slot_type *
>(
reinterpret_cast<char *
>(
this) + offset)));
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
Polymorphic optional.
Definition polymorphic_optional.hpp:39
A wait-free multiple-producer/single-consumer fifo designed for absolute performance.
Definition wfree_fifo.hpp:34
auto take_one(Func &&func) noexcept
Take one message from the fifo slot.
Definition wfree_fifo.hpp:69
void take_all(Operation const &operation) noexcept
Take all message from the queue.
Definition wfree_fifo.hpp:85
bool empty() const noexcept
Check if fifo is empty.
Definition wfree_fifo.hpp:56
hi_force_inline auto emplace_and_invoke(Func &&func, Args &&...args) noexcept
Create an message in-place on the fifo.
Definition wfree_fifo.hpp:98