Skip to content

Commit

Permalink
Cleanup only for Linux (#1497)
Browse files Browse the repository at this point in the history
* Cleanup only for Linux (other unix may require some improvement for this approach)

* fix forgotten file
  • Loading branch information
yellowhatter authored Oct 2, 2024
1 parent 79885ef commit 15a84de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions commons/zenoh-shm/src/posix_shm/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-shm/src/posix_shm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 8 additions & 8 deletions commons/zenoh-shm/src/posix_shm/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ShmLock>, // <---|
}

#[cfg(unix)]
#[cfg(target_os = "linux")]
impl<ID> Drop for Segment<ID>
where
rand::distributions::Standard: rand::distributions::Distribution<ID>,
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -115,7 +115,7 @@ where
return Ok(Segment {
shmem,
id,
#[cfg(unix)]
#[cfg(target_os = "linux")]
_lock: Some(lock),
});
}
Expand All @@ -131,7 +131,7 @@ where
pub fn open(id: ID, id_prefix: &str) -> ZResult<Self> {
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)?;

Expand All @@ -148,7 +148,7 @@ where
Ok(Self {
shmem,
id,
#[cfg(unix)]
#[cfg(target_os = "linux")]
_lock: Some(lock),
})
}
Expand Down

0 comments on commit 15a84de

Please sign in to comment.