Skip to main content

Module refcount

Module refcount 

Source
Expand description

Refcount fast paths — Rust mirrors of lean.h:536–563.

The header encodes the runtime mode in the RC sign:

  • m_rc > 0 — single-threaded: bump or decrement in place.
  • m_rc < 0 — multi-threaded: RC is negated; fetch_sub is the relaxed atomic decrement, mirroring atomic_fetch_sub_explicit(.., relaxed) in lean.h.
  • m_rc == 0 — persistent (compact regions); never refcounted.

Each mirror reaches m_rc through AtomicI32::from_ptr so the actual load / store / fetch_sub call site sees a safe &AtomicI32.

Functions§

lean_dec
Decrement o’s refcount, or no-op for scalar-tagged pointers (lean.h:563).
lean_dec_ref
Decrement o’s refcount, taking the cold path to free if it reaches zero (lean.h:554–560).
lean_dec_ref_cold
Cold path for refcount-zero decrement (lean.h:552). Invoked by lean_dec_ref when the live count would cross to zero and the object actually needs freeing.
lean_inc
Bump o’s refcount by one, or no-op for scalar-tagged pointers (lean.h:561).
lean_inc_n
Bump o’s refcount by n, or no-op for scalar-tagged pointers (lean.h:562).
lean_inc_ref
Bump o’s refcount by one (lean.h:548–550).
lean_inc_ref_n
Bump o’s reference count by n (lean.h:536–546, lean_inc_ref_n).
lean_mark_mt
Mark a heap object — and everything reachable from it — as multi-threaded (lean.h:612).
lean_mark_persistent
Mark a heap object as persistent so its refcount is no longer updated (lean.h:613).