Skip to content

Commit

Permalink
- remove dependency in zenoh-buffers
Browse files Browse the repository at this point in the history
- make periodic_task compile on win
  • Loading branch information
yellowhatter committed Mar 13, 2024
1 parent 4dd2611 commit 469ff3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion commons/zenoh-buffers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ test = ["rand"]
[dependencies]
rand = { workspace = true, optional = true }
zenoh-collections = { workspace = true, default-features = false }
zenoh-core = { workspace = true, default-features = false }
21 changes: 10 additions & 11 deletions commons/zenoh-buffers/src/zslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use core::{
ops::{Deref, Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive},
option,
};
use zenoh_core::zcondfeat;

/*************************************/
/* ZSLICE BUFFER */
Expand Down Expand Up @@ -59,11 +58,11 @@ pub trait ZSliceBuffer: Send + Sync + fmt::Debug {
/// on "shared-memory" feature
#[inline]
pub unsafe fn as_mut_slice_featureless<T: ZSliceBuffer + ?Sized>(slice: &mut T) -> &mut [u8] {
zcondfeat!(
"shared-memory",
slice.as_mut_slice_unchecked(),
slice.as_mut_slice()
)
#[cfg(feature = "shared-memory")]
return slice.as_mut_slice_unchecked();

#[cfg(not(feature = "shared-memory"))]
slice.as_mut_slice()
}

impl ZSliceBuffer for Vec<u8> {
Expand Down Expand Up @@ -527,11 +526,11 @@ mod tests {
let range = zslice.range();
let mbuf = Arc::get_mut(&mut zslice.buf).unwrap();

let mut_slice = zcondfeat!(
"shared-memory",
mbuf.as_mut_slice().unwrap(),
mbuf.as_mut_slice()
);
#[cfg(feature = "shared-memory")]
let mut_slice = mbuf.as_mut_slice().unwrap();
#[cfg(not(feature = "shared-memory"))]
let mut_slice = mbuf.as_mut_slice();

mut_slice[range][..buf.len()].clone_from_slice(&buf[..]);

assert_eq!(buf.as_slice(), zslice.as_slice());
Expand Down
18 changes: 14 additions & 4 deletions commons/zenoh-shm/src/watchdog/periodic_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ use std::{
#[cfg(not(feature = "test"))]
use log::error;
use log::warn;

use thread_priority::ThreadBuilder;
#[cfg(unix)]
use thread_priority::{
set_current_thread_priority, RealtimeThreadSchedulePolicy, ThreadBuilder, ThreadPriority, ThreadPriorityValue, ThreadSchedulePolicy::Realtime
set_current_thread_priority, RealtimeThreadSchedulePolicy, ThreadPriority, ThreadPriorityValue, ThreadSchedulePolicy::Realtime
};

pub struct PeriodicTask {
Expand All @@ -45,11 +48,18 @@ impl PeriodicTask {
let running = Arc::new(AtomicBool::new(true));

let c_running = running.clone();
let _ = ThreadBuilder::default()

#[cfg(unix)]
let builder = ThreadBuilder::default()
.name(name)
.policy(Realtime(RealtimeThreadSchedulePolicy::Fifo))
.priority(ThreadPriority::Min)
.spawn(move |result| {
.priority(ThreadPriority::Min);

#[cfg(windows)]
let builder = ThreadBuilder::default().name(name);

let _ = builder.spawn(move |result| {
#[cfg(unix)]
if let Err(e) = result {
warn!("{:?}: error setting realtime FIFO scheduling policy for thread: {:?}, will run with the default one...", std::thread::current().name(), e);

Expand Down

0 comments on commit 469ff3d

Please sign in to comment.