pub struct ShmMap { /* private fields */ }Expand description
A generic store for mapping names to Shared Memory pointers.
_context keeps the Arc<ShmContext> (and therefore the underlying
Shmem mapping) alive for as long as any ShmMap clone exists. Without
this anchor, dropping or replacing the original Arc<ShmContext> (e.g.
when a new configure_shm arrives) would munmap the segment and leave
the map’s raw pointers dangling — and the next write through one of them
would segfault.
Implementations§
Source§impl ShmMap
impl ShmMap
Sourcepub fn new(pointers: HashMap<String, ShmPtr>) -> Self
pub fn new(pointers: HashMap<String, ShmPtr>) -> Self
Build an ShmMap with no anchored context. Only safe when the caller
guarantees that the pointers’ backing memory outlives every ShmMap
clone. Prefer with_context for anything sourced from a real
ShmContext::resolve / resolve_shm_pointers call.
Sourcepub fn with_context(
pointers: HashMap<String, ShmPtr>,
context: Arc<ShmContext>,
) -> Self
pub fn with_context( pointers: HashMap<String, ShmPtr>, context: Arc<ShmContext>, ) -> Self
Build an ShmMap that anchors its lifetime to context. The Arc
keeps the Shmem mapping alive even if its original owner (e.g. the
IPC client’s shm_context slot) is later replaced or dropped.
pub fn get<T>(&self, name: &str) -> Option<*mut T>
pub fn get_raw(&self, name: &str) -> Option<usize>
Sourcepub unsafe fn read<T: Copy>(&self, name: &str) -> Option<T>
pub unsafe fn read<T: Copy>(&self, name: &str) -> Option<T>
Read a value from shared memory. SAFETY: Caller must ensure T matches the type of data at the pointer.