pub struct AdmissionGuard { /* private fields */ }Expand description
A held transfer slot and its memory reservation. Releasing both is
Drop, not a method, so no error path — and no panic — can skip it.
That is the whole answer to “an operation that ERRORS must still release”:
there is no release call to forget, because unwinding runs Drop.
Implementations§
Source§impl AdmissionGuard
impl AdmissionGuard
Sourcepub fn entered_service(&self)
pub fn entered_service(&self)
The operation’s work has actually started. Files this item’s sojourn against its class’s window.
Called by the caller and not by the gate, because only the caller knows
when the waiting stopped. In crate::server that is the first line of
the spawned transfer task: everything between admission and there is the
runtime’s ready queue and the blocking-pool handoff, which is exactly the
invisible queue this whole module exists to make visible.
One-shot: a second call is ignored rather than filing a second, longer sample for the same item.
Sourcepub fn reserve_more(&self, bytes: u64) -> Option<Growth>
pub fn reserve_more(&self, bytes: u64) -> Option<Growth>
Charge this transfer for bytes more on the wire.
Called by the transport as bytes actually move, in either direction, and
this is what makes the memory gate cost-based rather than flat: the
admission reservation (OpClass::admission_bytes) is the entry cost,
and everything proportional to the transfer arrives here.
Charges WIRE_MEMORY_NUMERATOR/WIRE_MEMORY_DENOMINATOR of the
bytes, in steps of WIRE_RESERVE_STEP, so a per-byte quantity never
becomes a per-byte decision. Returns Some(Growth) on the calls that
actually charged and None in between, so a caller can log the
overdraw without testing for it.
It cannot refuse — see Growth. What an overdraw does is stop new
admissions until this transfer finishes.