36class alignas(SlotSize) wfree_fifo {
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;
48 constexpr wfree_fifo()
noexcept =
default;
49 wfree_fifo(wfree_fifo
const&) =
delete;
50 wfree_fifo(wfree_fifo&&) =
delete;
51 wfree_fifo& operator=(wfree_fifo
const&) =
delete;
52 wfree_fifo& operator=(wfree_fifo&&) =
delete;
58 [[nodiscard]]
bool empty() const noexcept
60 return _head.load(std::memory_order::relaxed) == _tail;
70 template<
typename Func>
86 template<
typename Operation>
87 void take_all(Operation
const& operation)
noexcept
99 template<
typename Message,
typename Func,
typename... Args>
109 hilet offset = _head.fetch_add(slot_size, std::memory_order::relaxed);
113 template<
typename Func,
typename Object>
114 hi_force_inline
auto insert_and_invoke(Func&& func, Object&&
object)
noexcept
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
132 std::array<slot_type, num_slots> _slots = {};
133 std::atomic<uint16_t> _head = 0;
134 std::array<std::byte, hi::hardware_destructive_interference_size> _dummy = {};
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)));
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