cheatah
Class

memory::Owner

The sole owner + scheduling coordinator for one T.

Non-copyable and pinned, so the object never moves; every access goes through a request → acquire → lease.

Template parameters
T

the owned type.

Functions

fn Owner · 3 overloads
Owner(T &&value, policy pol=policy::interleave)source#
Owner(const Owner &)=deletesource#
Owner(Owner &&)=deletesource#

Take sole ownership by MOVING value in — the object is consumed (its resources move into the Owner), never copied.

An lvalue won't bind here (bind an rvalue: own(std::move(x))).

Parameters
value

the object to take ownership of (moved in).

pol

the scheduling policy (interleave / writes_first).

Complexity

O(1) plus moving value.

Allocation

one read-generation gate (std::make_shared); the value's own storage just moves.

Concurrency

construct before sharing; the pinned Owner must outlive every lease and every thread that uses it.

fn operator= · 2 overloads
Owner & operator=(const Owner &)=deletesource#
Owner & operator=(Owner &&)=deletesource#
fn Request< Lease< T, read > > rread() source#

Request a shared READ lease.

Blocks — in THIS call: the grant is synchronous, so the returned request is already fulfilled — only while a write is pending/active or queued; otherwise many read leases coexist.

Returns

a request for a read lease.

Complexity

O(1) amortized.

Allocation

the request's promise/future.

Concurrency

callable from any thread; readers share. Writer-preference: this waits while any write is active, suspended, or queued, so writers cannot starve.

Warning

requesting while the SAME thread still holds a lease on this owner can deadlock (a queued write makes the grant wait on that very lease) — renewal is release, then re-request.

fn Request< Lease< T, write > > rwrite() source#

Request an exclusive WRITE lease at compile-time priority (a plain int or the caller's enum; higher = served first, ties FIFO).

priority < 0 (spell it memory::immediate) is an immediate-write. Blocks in THIS call — the grant is synchronous, so the returned request is already fulfilled — until the readers drain and this write wins the queue.

Template parameters
priority

the compile-time write priority.

Returns

a request for a write lease.

Complexity

O(log k) to enqueue among k waiters (O(1) immediate), plus the blocking wait.

Allocation

the request's promise/future, two fresh gates (std::make_shared: this write's own + the next read generation's), plus one queue-ticket slot (amortized) for a non-immediate write.

Concurrency

callable from any thread. Drain-before-write: flips the current read generation's gate and waits until every reader has released and no other write is active; an immediate-write skips the queue and additionally preempts a cooperating active writer (which resumes after).

Warning

requesting while the SAME thread still holds a lease on this owner deadlocks (the drain waits on that very lease) — release first, then re-request.

fn bool can_read() const source#
fn std::shared_ptr< detail::Gate > make_gate() source#
fn Request< Lease< T, write > > grant_write(long long prio) source#
fn Request< Lease< T, write > > grant_immediate() source#
fn void release_read() source#
fn void release_write() source#
fn void release_immediate() source#

Constants & variables

var T value_ source#
var policy policy_ source#
var std::mutex mtx_ source#
var std::condition_variable cv_ source#
var long long readers_ source#

active read leases.

var bool writer_ source#

an active (non-suspended) write lease.

var bool writer_suspended_ source#

active writer paused for an immediate-write.

var bool immediate_ source#

an immediate-write holds exclusive access.

var std::shared_ptr< detail::Gate > read_gate_ source#

current read generation's yield gate.

var std::shared_ptr< detail::Gate > writer_gate_ source#

the active writer's gate (for preempt/resume).

var std::priority_queue< Ticket, std::vector< Ticket >, ServedLater > wq_ source#

waiting non-immediate writes.

var std::uint64_t seq_ source#