MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ drain()

template<typename T >
template<typename Finish >
requires std::invocable<Finish, T&>
void MayaFlux::Memory::SweepList< T >::drain ( Finish  finish)
inline

Blocking pass that finalizes every item currently held.

Atomically takes the entire chain and calls finish(item) on every one of them unconditionally, freeing each link as it goes. Intended for teardown paths, destructors, and explicit "wait for everything" calls, where finish itself performs the blocking wait (for example future.get()).

Items pushed by other threads after the chain is taken are not included and remain for a later call.

Template Parameters
FinishCallable (T&) -> void.
Parameters
finishFinalizer, invoked once per item, in unspecified order.

Definition at line 184 of file SweepList.hpp.

185 {
186 Link* chain = m_head.exchange(nullptr, std::memory_order_acquire);
187
188 while (chain) {
189 Link* next = chain->next;
190 std::unique_ptr<Link> owned(chain);
191 std::invoke(finish, owned->value);
192 chain = next;
193 }
194
195 m_count.store(0, std::memory_order_relaxed);
196 }
BufferProcessingChain * chain
std::atomic< Link * > m_head
std::atomic< size_t > m_count

References chain, MayaFlux::Memory::SweepList< T >::m_count, MayaFlux::Memory::SweepList< T >::m_head, and MayaFlux::Memory::SweepList< T >::Link::next.

Referenced by MayaFlux::Parallel::AsyncGroup< T >::take_errors(), and MayaFlux::Memory::SweepList< T >::~SweepList().

+ Here is the caller graph for this function: