39class alignas(SlotSize) wfree_fifo {
41 static_assert(std::has_single_bit(SlotSize),
"Only power-of-two number of messages size allowed.");
42 static_assert(SlotSize < 65536);
49 constexpr static std::size_t num_slots = fifo_size / slot_size;
51 constexpr wfree_fifo()
noexcept =
default;
52 wfree_fifo(wfree_fifo
const&) =
delete;
53 wfree_fifo(wfree_fifo&&) =
delete;
54 wfree_fifo& operator=(wfree_fifo
const&) =
delete;
55 wfree_fifo& operator=(wfree_fifo&&) =
delete;
61 [[nodiscard]]
bool empty() const noexcept
63 return _head.load(std::memory_order::relaxed) == _tail;
73 template<
typename Func>
89 template<
typename Operation>
90 void take_all(Operation
const& operation)
noexcept
102 template<
typename Message,
typename Func,
typename... Args>
112 auto const offset = _head.fetch_add(slot_size, std::memory_order::relaxed);
116 template<
typename Func,
typename Object>
117 hi_force_inline
auto insert_and_invoke(Func&& func, Object&&
object)
noexcept
122 template<
typename Message,
typename... Args>
123 hi_force_inline
void emplace(Args&&...args)
noexcept
125 return emplace_and_invoke<Message>([](Message&) ->
void {},
std::forward<Args>(args)...);
128 template<
typename Object>
129 hi_force_inline
void insert(Object &&
object)
noexcept
135#if defined(__cpp_lib_hardware_interference_size)
136 constexpr static size_t destructive_interference_size = std::hardware_destructive_interference_size;
138 constexpr static size_t destructive_interference_size = 128;
141 std::array<slot_type, num_slots> _slots = {};
142 std::atomic<uint16_t> _head = 0;
143 std::array<std::byte, destructive_interference_size> _dummy = {};
148 hi_force_inline slot_type& get_slot(uint16_t offset)
noexcept
150 hi_axiom(offset % slot_size == 0);
152 return *std::launder(
153 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:103