Skip to main content

ShmRegion

Struct ShmRegion 

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

A mapped POSIX SHM region. Drop unmaps; unlink removes the underlying name and any companion lock file (only the creator should call it on shutdown).

Implementations§

Source§

impl ShmRegion

Source

pub fn validate_existing( name: &str, minimum_size: usize, ) -> Result<ShmValidation>

Validate an existing shared-memory object without creating, mapping, resetting, or unlinking it.

Returns ShmValidation::Missing when the name does not exist. A present object must be at least minimum_size bytes; larger objects are accepted because some platforms report page-rounded SHM sizes. The owning ring or table remains responsible for validating its own persisted ABI header after mapping.

Source

pub fn open_or_create(name: &str, size: usize) -> Result<Self>

Open or create a shared-memory segment of size bytes, memory-mapped read/write. Idempotent: if the segment already exists with the same name and enough mapped bytes, it is reused (created = false). First creation does ftruncate(size); later opens verify the existing object before mapping it. Some platforms report a page-rounded SHM size, so a larger st_size is valid; the owning data structure must verify its own header.

Source

pub fn open_or_create_locked( name: &str, size: usize, ) -> Result<(Self, ShmRegionLock)>

Open or create a region while holding its process lock through caller initialization. This prevents a peer from observing the interval between shm_open and the owning data structure’s initialized header.

Source

pub fn as_ptr(&self) -> *mut u8

Raw mapped pointer to the start of the region.

Source

pub fn len(&self) -> usize

Length of the mapped region (the size passed to open_or_create).

Source

pub fn is_empty(&self) -> bool

Source

pub fn created(&self) -> bool

True when this handle was the one that created the segment. Useful for picking which process performs first-time initialization of the header.

Source

pub fn lock_exclusive(&self) -> Result<ShmRegionLock>

Acquire an exclusive cross-process lock tied to this SHM name.

flock ownership is held by the kernel and is released when a process exits or the descriptor closes, including abnormal termination.

Remove the underlying segment name. Existing mappings stay valid until each process drops its ShmRegion. Use only on shutdown / fleet teardown by the process that owns lifecycle.

Trait Implementations§

Source§

impl Drop for ShmRegion

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 Send for ShmRegion

Source§

impl Sync for ShmRegion

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.