Skip to content

Commit

Permalink
[eclipse-iceoryx#200] Fix underflow in sleep time calculations in win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
elfenpiff committed Apr 29, 2024
1 parent e1617de commit 9d5aa9c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
26 changes: 13 additions & 13 deletions iceoryx2-bb/elementary/src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@
pub struct Alignment(usize);

impl Alignment {
pub const ALIGNMENT_1: Alignment = Alignment(1);
pub const ALIGNMENT_2: Alignment = Alignment(2);
pub const ALIGNMENT_4: Alignment = Alignment(4);
pub const ALIGNMENT_8: Alignment = Alignment(8);
pub const ALIGNMENT_16: Alignment = Alignment(16);
pub const ALIGNMENT_32: Alignment = Alignment(32);
pub const ALIGNMENT_64: Alignment = Alignment(64);
pub const ALIGNMENT_128: Alignment = Alignment(128);
pub const ALIGNMENT_256: Alignment = Alignment(256);
pub const ALIGNMENT_512: Alignment = Alignment(512);
pub const ALIGNMENT_1024: Alignment = Alignment(1024);
pub const ALIGNMENT_2048: Alignment = Alignment(2048);
pub const ALIGNMENT_4096: Alignment = Alignment(4096);
pub const ALIGN_1: Alignment = Alignment(1);
pub const ALIGN_2: Alignment = Alignment(2);
pub const ALIGN_4: Alignment = Alignment(4);
pub const ALIGN_8: Alignment = Alignment(8);
pub const ALIGN_16: Alignment = Alignment(16);
pub const ALIGN_32: Alignment = Alignment(32);
pub const ALIGN_64: Alignment = Alignment(64);
pub const ALIGN_128: Alignment = Alignment(128);
pub const ALIGN_256: Alignment = Alignment(256);
pub const ALIGN_512: Alignment = Alignment(512);
pub const ALIGN_1024: Alignment = Alignment(1024);
pub const ALIGN_2048: Alignment = Alignment(2048);
pub const ALIGN_4096: Alignment = Alignment(4096);

/// Creates a new [`Alignment`]. If the value is zero or not a power of 2
/// it returns [`None`].
Expand Down
11 changes: 7 additions & 4 deletions iceoryx2-pal/posix/src/windows/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ pub unsafe fn clock_nanosleep(
return Errno::EINVAL as _;
}

let time = Duration::from_secs((*rqtp).tv_sec as _)
+ Duration::from_nanos((*rqtp).tv_nsec as _)
- now.unwrap();
let future_time_point =
Duration::from_secs((*rqtp).tv_sec as _) + Duration::from_nanos((*rqtp).tv_nsec as _);

if now < future_time_point {
let sleep_time = future_time_point - now.unwrap();
std::thread::sleep(time);
}

std::thread::sleep(time);
Errno::ESUCCES as _
}

0 comments on commit 9d5aa9c

Please sign in to comment.