Skip to main content

SharedCursor

Struct SharedCursor 

Source
pub struct SharedCursor { /* private fields */ }
Expand description

A shared cursor that can be accessed across processes

This implements the disruptor pattern’s cursor concept for multi-process scenarios. Each cursor tracks a sequence position and can be safely shared between processes using shared memory with cache-line padding to prevent false sharing.

Implementations§

Source§

impl SharedCursor

Source

pub fn new_auto(initial_value: i64) -> MultiProcessResult<(Self, String)>

Create a new shared cursor with automatic naming

Source

pub fn new(name: &str, initial_value: i64) -> MultiProcessResult<Self>

Create a new shared cursor in a new shared memory segment (legacy method)

Source

pub fn recreate(name: &str, initial_value: i64) -> MultiProcessResult<Self>

Explicitly recreate a shared cursor by unlinking and creating a fresh segment.

This is intended for crash-restart recovery paths when a stale segment may remain after an unclean shutdown. This operation is destructive for any currently attached process using the same name.

Source

pub fn attach(name: &str) -> MultiProcessResult<Self>

Attach to an existing shared cursor in an existing shared memory segment

Source

pub fn new_or_attach(name: &str, initial_value: i64) -> MultiProcessResult<Self>

Create a new shared cursor, or attach to existing one if it already exists

Source

pub fn is_owner(&self) -> bool

Return whether this mapping currently owns unlink responsibility.

Source

pub fn set_owner(&mut self, is_owner: bool) -> bool

Transfer or release ownership of the underlying shared-memory name.

Consumer sequence cursors use this to become persistent restart anchors: the first attaching consumer may create the cursor segment, but it must not unlink that name when the process exits, or subsequent restarts would reset the logical consumer position back to the initial value.

Source

pub fn load(&self, ordering: Ordering) -> i64

Load the current value

Source

pub fn store(&self, value: i64, ordering: Ordering)

Store a new value

Source

pub fn compare_exchange( &self, current: i64, new: i64, success: Ordering, failure: Ordering, ) -> Result<i64, i64>

Compare and swap

Source

pub fn compare_exchange_weak( &self, current: i64, new: i64, success: Ordering, failure: Ordering, ) -> Result<i64, i64>

Compare and swap (weak version, may fail spuriously)

Source

pub fn fetch_add(&self, val: i64, ordering: Ordering) -> i64

Fetch and add

Source

pub fn swap(&self, val: i64, ordering: Ordering) -> i64

Atomic exchange

Trait Implementations§

Source§

impl Clone for SharedCursor

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Drop for SharedCursor

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl SharedCursorTrait<i64> for SharedCursor

Source§

fn load(&self, ordering: Ordering) -> i64

Load the current value with the given memory ordering
Source§

fn store(&self, value: i64, ordering: Ordering)

Store a new value with the given memory ordering
Source§

fn compare_exchange( &self, current: i64, new: i64, success: Ordering, failure: Ordering, ) -> Result<i64, i64>

Compare and exchange operation with success and failure memory orderings
Source§

impl Send for SharedCursor

Source§

impl Sync for SharedCursor

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V