memory::Lease
The only handle to an owned object — a move-only RAII lease granted by an Owner.
M is read (shared) or write/write_renewable (exclusive). Reads go through read(...); a write lease sets through write(...). The lease holds a direct pointer to the object plus the release callback it fires on destruction.
T | the owned type ( |
M | the mode. |
Functions
Lease · 3 overloads
The owner's grant path (called only by Owner).
O(1).
none.
obj | pointer to the owned object. |
gate | the generation gate that carries the yield signal. |
release | callback fired once on destruction to tell the owner this lease is done. |
called by the owner with its coordinator mutex held — never construct one yourself.
operator= · 2 overloads
Move-assign: release ours, then take over o's grant.
o | source. |
*this.
O(1).
none.
Release the lease (fires the owner's release callback if still held).
O(1).
none.
the release callback takes the owner's coordinator mutex and wakes waiting requests (a draining writer proceeds once the last reader releases here).
Memory.WriteWaitsForReadersToDrainread · 3 overloads
Read the whole object.
Available on every lease.
a const T& — never a copy or T*.
O(1).
none.
race-free while the lease is held: a writer cannot proceed until this lease releases (yielding on !valid() is cooperative, not forced). No lock is taken here.
Read the first element (containers with front(): vector / deque / list / string …).
a const reference to the first element.
O(1).
none.
Read the last element (containers with back()).
a const reference to the last element.
O(1).
none.
write · 3 overloads
Replace the whole object: w.write(value).
The primary write form. Write / write_renewable only.
value | the new value (moved in). |
O(1) plus assigning value.
whatever T's assignment allocates.
exclusive: no reader or other writer coexists while this lease is valid. A writer that observed !valid() (an immediate-write preempted it) must wait for valid() to flip back before writing again — writing while suspended races with the immediate-write.
MemoryCheatah.ScalarWriteReadModifyWriteStill ours?
true until the owner asks us to yield (a writer waiting; an immediate-write). The holder observing !valid() is how the owner learns it has paused.
whether the lease is still valid.
O(1).
none.
an atomic acquire load; the first observation of a stop acks and wakes the owner (that one call briefly takes the owner's mutex) — polling this from the holding thread is what lets a drain/preempt make progress. The lease handle itself is not internally synchronized: poll from the thread that holds the lease.
Asked to yield?
The negation of valid().
true once the owner needs the lease back.
O(1).
none.
MemoryCheatah.ReadLeaseValidStateRegister the "what to do if the owner interrupts me" handler; fires once, in the holder's thread, the first time valid() observes the stop.
Replaces any previous handler.
O(1).
one callback holder (the handler std::function, moved in — nothing beyond its own state).
handler | the callback to run when the owner asks this lease to yield. |
the handler never fires asynchronously — only from inside a valid() call, on the thread that polls it.
Constants & variables
direct pointer to the object (one deref).
shared yield signal (per generation / active write).
tells the owner "I'm done" (fired once, in dtor).
optional push handler when asked to yield.
has on_interrupt_ fired for the current stop?
