86 drain([](T&)
noexcept { });
100 std::unique_ptr<Link> owned = std::make_unique<Link>(std::move(
value),
nullptr);
105 Link* node = owned.release();
107 node->
next =
m_head.load(std::memory_order_relaxed);
108 while (!
m_head.compare_exchange_weak(
110 std::memory_order_release, std::memory_order_relaxed)) {
113 m_count.fetch_add(1, std::memory_order_relaxed);
136 template <
typename Pred,
typename Finish>
137 requires std::invocable<Pred, T&> && std::invocable<Finish, T&>
138 void sweep(Pred ready, Finish finish)
142 Link* survivors =
nullptr;
143 size_t reclaimed = 0;
148 if (std::invoke(ready,
chain->value)) {
149 std::unique_ptr<Link> owned(
chain);
150 std::invoke(finish, owned->value);
153 chain->next = survivors;
164 m_count.fetch_sub(reclaimed, std::memory_order_relaxed);
182 template <
typename Finish>
183 requires std::invocable<Finish, T&>
190 std::unique_ptr<Link> owned(
chain);
191 std::invoke(finish, owned->value);
195 m_count.store(0, std::memory_order_relaxed);
206 return m_count.load(std::memory_order_relaxed);
214 [[nodiscard]]
bool empty() const noexcept
216 return m_head.load(std::memory_order_acquire) ==
nullptr;
227 Link* tail = survivors;
231 tail->
next =
m_head.load(std::memory_order_relaxed);
232 while (!
m_head.compare_exchange_weak(
233 tail->
next, survivors,
234 std::memory_order_release, std::memory_order_relaxed)) {
238 alignas(64) std::atomic<Link*>
m_head {
nullptr };
239 alignas(64) std::atomic<size_t>
m_count { 0 };
BufferProcessingChain * chain
void reattach(Link *survivors) noexcept
void push(T value) noexcept
Publishes value for later sweep() or drain().
void drain(Finish finish)
Blocking pass that finalizes every item currently held.
bool empty() const noexcept
Whether the list currently holds no items.
void sweep(Pred ready, Finish finish)
Non-blocking pass over every currently held item.
SweepList() noexcept=default
std::atomic< Link * > m_head
std::atomic< size_t > m_count
size_t approx_size() const noexcept
Approximate number of items currently held.
Lock-free, unbounded, multi-producer collection of in-flight items.