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
impl ShmRegion
Sourcepub fn open_or_create(name: &str, size: usize) -> Result<Self>
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.
Sourcepub fn open_or_create_locked(
name: &str,
size: usize,
) -> Result<(Self, ShmRegionLock)>
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.
pub fn is_empty(&self) -> bool
Sourcepub fn created(&self) -> bool
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.
Sourcepub fn lock_exclusive(&self) -> Result<ShmRegionLock>
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.