From 15a84dee3f85000c11fab81cc0028bbf2f907dc2 Mon Sep 17 00:00:00 2001 From: yellowhatter <104833606+yellowhatter@users.noreply.github.com> Date: Wed, 2 Oct 2024 12:52:04 +0300 Subject: [PATCH] Cleanup only for Linux (#1497) * Cleanup only for Linux (other unix may require some improvement for this approach) * fix forgotten file --- commons/zenoh-shm/src/posix_shm/cleanup.rs | 4 ++-- commons/zenoh-shm/src/posix_shm/mod.rs | 2 +- commons/zenoh-shm/src/posix_shm/segment.rs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/commons/zenoh-shm/src/posix_shm/cleanup.rs b/commons/zenoh-shm/src/posix_shm/cleanup.rs index 538aa6d3c..f7f6256c7 100644 --- a/commons/zenoh-shm/src/posix_shm/cleanup.rs +++ b/commons/zenoh-shm/src/posix_shm/cleanup.rs @@ -14,12 +14,12 @@ pub(crate) use platform::cleanup_orphaned_segments; -#[cfg(not(unix))] +#[cfg(not(target_os = "linux"))] mod platform { pub(crate) fn cleanup_orphaned_segments() {} } -#[cfg(unix)] +#[cfg(target_os = "linux")] mod platform { use std::fs; diff --git a/commons/zenoh-shm/src/posix_shm/mod.rs b/commons/zenoh-shm/src/posix_shm/mod.rs index b56814e1d..c9d3af32e 100644 --- a/commons/zenoh-shm/src/posix_shm/mod.rs +++ b/commons/zenoh-shm/src/posix_shm/mod.rs @@ -13,7 +13,7 @@ // pub mod array; -#[cfg(unix)] +#[cfg(target_os = "linux")] pub(crate) mod segment_lock; tested_crate_module!(segment); pub(crate) mod cleanup; diff --git a/commons/zenoh-shm/src/posix_shm/segment.rs b/commons/zenoh-shm/src/posix_shm/segment.rs index 7bb08610d..09bdb448d 100644 --- a/commons/zenoh-shm/src/posix_shm/segment.rs +++ b/commons/zenoh-shm/src/posix_shm/segment.rs @@ -20,7 +20,7 @@ use zenoh_result::{bail, zerror, ZResult}; use crate::cleanup::CLEANUP; -#[cfg(unix)] +#[cfg(target_os = "linux")] use super::segment_lock::unix::{ExclusiveShmLock, ShmLock}; const SEGMENT_DEDICATE_TRIES: usize = 100; @@ -34,11 +34,11 @@ where { shmem: Shmem, // <-------------| id: ID, // | - #[cfg(unix)] // | location of these two fields matters! + #[cfg(target_os = "linux")] // | location of these two fields matters! _lock: Option, // <---| } -#[cfg(unix)] +#[cfg(target_os = "linux")] impl Drop for Segment where rand::distributions::Standard: rand::distributions::Distribution, @@ -80,7 +80,7 @@ where let id: ID = rand::thread_rng().gen(); let os_id = Self::os_id(id.clone(), id_prefix); - #[cfg(unix)] + #[cfg(target_os = "linux")] // Create lock to indicate that segment is managed let lock = { match ShmLock::create(&os_id) { @@ -106,7 +106,7 @@ where tracing::debug!( "Created SHM segment, size: {alloc_size}, prefix: {id_prefix}, id: {id}" ); - #[cfg(unix)] + #[cfg(target_os = "linux")] let shmem = { let mut shmem = shmem; shmem.set_owner(false); @@ -115,7 +115,7 @@ where return Ok(Segment { shmem, id, - #[cfg(unix)] + #[cfg(target_os = "linux")] _lock: Some(lock), }); } @@ -131,7 +131,7 @@ where pub fn open(id: ID, id_prefix: &str) -> ZResult { let os_id = Self::os_id(id.clone(), id_prefix); - #[cfg(unix)] + #[cfg(target_os = "linux")] // Open lock to indicate that segment is managed let lock = ShmLock::open(&os_id)?; @@ -148,7 +148,7 @@ where Ok(Self { shmem, id, - #[cfg(unix)] + #[cfg(target_os = "linux")] _lock: Some(lock), }) }