Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
slot.hpp File Reference

Publishing a value built off the audio thread, and reclaiming the old one without ever calling a destructor on the audio thread. More...

#include <pulp/runtime/spsc_queue.hpp>
#include <atomic>
#include <cassert>
#include <cstddef>
#include <memory>
#include <thread>
#include <utility>
#include <vector>

Go to the source code of this file.

Classes

class  pulp::runtime::Slot< T >
 Lock-free publication to a reader that must never block. More...
class  pulp::runtime::Slot< T >::ReadGuard
 RAII pin. More...
class  pulp::runtime::Handoff< T, RetireCapacity >
 Lock-free transfer of ownership to a reader that must never block, plus a ring for handing the displaced value back so the audio thread never frees. More...

Namespaces

namespace  pulp
namespace  pulp::runtime

Detailed Description

Publishing a value built off the audio thread, and reclaiming the old one without ever calling a destructor on the audio thread.

This is the one rule both types below enforce:

The audio thread never allocates, never blocks, and never frees.

Deallocation is a blocking OS operation, so the retired value must always be destroyed somewhere else. Pulp had four separate hand-rolled solutions to this before these types existed; Slot and Handoff are the two shapes those four collapse into.

Two publication modes, because there are genuinely two:

Slot<T> Handoff<T>
audio thread reads a shared value takes ownership of the value
value is immutable while published mutable by its owner
reclamation control thread, once readers drain worker thread, via a retire ring
reader pin yes (ReadGuard) n/a — single owner

Pick Slot when the audio thread only looks at the value (a compiled graph, a wavetable, a lookup table). Pick Handoff when the audio thread owns and mutates it (a convolver IR carrying partition state and input history).

Both are single-producer / audio-thread-consumer. Neither is a general MPMC container, and neither tries to be.

Note
Slot gives you grace after retire. If you need quiescence before publish — proving the old value is not in process() so you can serialize state out of it — that is a different requirement, and format::ProcessorHotSwapSlot keeps its own mechanism for it.