pub struct MemoryLedger { /* private fields */ }Expand description
Gate 2: a budget and a counter. Never a probe.
Implementations§
Source§impl MemoryLedger
impl MemoryLedger
Sourcepub fn new(budget: u64) -> MemoryLedger
pub fn new(budget: u64) -> MemoryLedger
A ledger with budget bytes to give out.
Sourcepub fn try_reserve(&self, bytes: u64) -> bool
pub fn try_reserve(&self, bytes: u64) -> bool
Reserve bytes, or refuse.
A compare-and-swap loop rather than “load, check, add”: between a load and an add, two concurrent admissions both see room and both take it, and a budget that can be exceeded by the number of racing threads is not a budget. Nothing is allocated here and nothing is allocated by the caller before here — the refusal arrives before the cost.
Sourcepub fn charge(&self, bytes: u64) -> bool
pub fn charge(&self, bytes: u64) -> bool
Charge bytes whether or not they fit, and say which it was.
The reserve path for an operation that is already running: see
Growth for why this cannot refuse. The counter is allowed to exceed
the budget, and while it does, MemoryLedger::try_reserve refuses
every new admission — which is the whole mechanism by which one enormous
transfer quiets the box instead of taking it down.