34class alignas(SlotSize) wfree_fifo {
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;
46 constexpr wfree_fifo()
noexcept =
default;
47 wfree_fifo(wfree_fifo
const&) =
delete;
48 wfree_fifo(wfree_fifo&&) =
delete;
49 wfree_fifo& operator=(wfree_fifo
const&) =
delete;
50 wfree_fifo& operator=(wfree_fifo&&) =
delete;
56 [[nodiscard]]
bool empty() const noexcept
58 return _head.load(std::memory_order::relaxed) == _tail;
68 template<
typename Func>
84 template<
typename Operation>
85 void take_all(Operation
const& operation)
noexcept
97 template<
typename Message,
typename Func,
typename... Args>
107 hilet offset = _head.fetch_add(slot_size, std::memory_order::relaxed);
111 template<
typename Func,
typename Object>
112 hi_force_inline
auto insert_and_invoke(Func&& func, Object&&
object)
noexcept
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
130 std::array<slot_type, num_slots> _slots = {};
131 std::atomic<uint16_t> _head = 0;
132 std::array<std::byte, hi::hardware_destructive_interference_size> _dummy = {};
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
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