pub struct SharedAtom {
pub cell: Arc<ArcSwap<SharedValue>>,
pub meta: Mutex<Option<SharedValue>>,
}Expand description
A cross-isolate mutable reference backed by a lock-free ArcSwap.
reset! and swap! promote the new value and perform an atomic pointer
swap — no locking, O(1) for simple resets, O(retries) for CAS-retry
swap! under write contention. deref is a single atomic load plus an
Arc reference-count bump.
Wrapped in Value::SharedAtom(Arc<SharedAtom>). The Arc gives the atom
identity (pointer equality) and allows any number of isolates to hold a
reference.
Fields§
§cell: Arc<ArcSwap<SharedValue>>§meta: Mutex<Option<SharedValue>>Implementations§
pub fn new(val: SharedValue) -> Self
Sourcepub fn deref_val(&self) -> Arc<SharedValue> ⓘ
pub fn deref_val(&self) -> Arc<SharedValue> ⓘ
Load the current value. Lock-free atomic load + refcount bump.
Sourcepub fn reset(&self, val: SharedValue) -> Arc<SharedValue> ⓘ
pub fn reset(&self, val: SharedValue) -> Arc<SharedValue> ⓘ
Atomically replace the value and return the new Arc.
Sourcepub fn swap<F>(&self, f: F) -> Arc<SharedValue> ⓘ
pub fn swap<F>(&self, f: F) -> Arc<SharedValue> ⓘ
CAS-retry swap: apply f to the current value and store the result.
Returns the new value. Retries automatically if another writer races.
Sourcepub fn compare_and_set(
&self,
current: &Arc<SharedValue>,
new: SharedValue,
) -> bool
pub fn compare_and_set( &self, current: &Arc<SharedValue>, new: SharedValue, ) -> bool
Single lock-free compare-and-set. Atomically stores new iff the cell
still holds current (by Arc identity). Returns true on success.
This is the primitive used by Clojure-level compare-and-set! and by the
retry loop behind swap!: a caller that needs to run arbitrary
(interpreter) code between the load and the store cannot use the closure
form of [swap], so it loads via deref_val, computes
the next value, then commits with this method, retrying on contention.