From 293a2e991d592362dd5524085a10ad518829bc84 Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 11 Mar 2026 14:37:16 +0000 Subject: [PATCH 1/2] do not derive Copy for timespec --- src/header/bits_time/mod.rs | 2 +- src/header/pthread/mutex.rs | 2 +- src/header/semaphore/mod.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/header/bits_time/mod.rs b/src/header/bits_time/mod.rs index 801ed63d00..7c3e031ec9 100644 --- a/src/header/bits_time/mod.rs +++ b/src/header/bits_time/mod.rs @@ -5,7 +5,7 @@ use crate::{ /// See . #[repr(C)] -#[derive(Clone, Copy, Default, Debug)] +#[derive(Clone, Default, Debug)] pub struct timespec { pub tv_sec: time_t, pub tv_nsec: c_long, diff --git a/src/header/pthread/mutex.rs b/src/header/pthread/mutex.rs index 20d2b0f69a..9f53257dbf 100644 --- a/src/header/pthread/mutex.rs +++ b/src/header/pthread/mutex.rs @@ -76,7 +76,7 @@ pub unsafe extern "C" fn pthread_mutex_timedlock( mutex: *mut pthread_mutex_t, abstime: ×pec, ) -> c_int { - let relative = match timespec_realtime_to_monotonic(*abstime) { + let relative = match timespec_realtime_to_monotonic(abstime.clone()) { Ok(relative) => relative, Err(err) => return e(Err(err)), }; diff --git a/src/header/semaphore/mod.rs b/src/header/semaphore/mod.rs index 973b7dee74..70a8b8a7d6 100644 --- a/src/header/semaphore/mod.rs +++ b/src/header/semaphore/mod.rs @@ -96,7 +96,7 @@ pub unsafe extern "C" fn sem_clockwait( clock_id: clockid_t, abstime: *const timespec, ) -> c_int { - if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), clock_id) {}; // TODO handle error + if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { (*abstime).clone() }), clock_id) {}; // TODO handle error 0 } @@ -104,7 +104,8 @@ pub unsafe extern "C" fn sem_clockwait( /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn sem_timedwait(sem: *mut sem_t, abstime: *const timespec) -> c_int { - if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { *abstime }), CLOCK_REALTIME) {}; // TODO handle error + if let Ok(()) = unsafe { get(sem) }.wait(Some(&unsafe { (*abstime).clone() }), CLOCK_REALTIME) { + }; // TODO handle error 0 } From 3ea60eeb72ea6b85ca86545c2bb0f860966de887 Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 11 Mar 2026 14:51:06 +0000 Subject: [PATCH 2/2] timespec clone followup for redox --- src/platform/redox/mod.rs | 6 +++--- src/platform/redox/timer.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 33508c2d24..5f527cfaa3 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1367,7 +1367,7 @@ impl Pal for Sys { Self::clock_gettime(timer_st.clockid, Out::from_mut(&mut now))?; if timer_st.evp.sigev_notify == SIGEV_NONE { - if timespec::subtract(timer_st.next_wake_time.it_value, now).is_none() { + if timespec::subtract(timer_st.next_wake_time.it_value.clone(), now.clone()).is_none() { // error here means the timer is disarmed let _ = timer_update_wake_time(timer_st); } @@ -1378,8 +1378,8 @@ impl Pal for Sys { itimerspec::default() } else { itimerspec { - it_interval: timer_st.next_wake_time.it_interval, - it_value: timespec::subtract(timer_st.next_wake_time.it_value, now) + it_interval: timer_st.next_wake_time.it_interval.clone(), + it_value: timespec::subtract(timer_st.next_wake_time.it_value.clone(), now) .unwrap_or_default(), } }); diff --git a/src/platform/redox/timer.rs b/src/platform/redox/timer.rs index b79a27dc02..8a46f8a550 100644 --- a/src/platform/redox/timer.rs +++ b/src/platform/redox/timer.rs @@ -86,7 +86,7 @@ pub(crate) fn timer_update_wake_time(timer_st: &mut timer_internal_t) -> Result< } else { let mut now = timespec::default(); Sys::clock_gettime(timer_st.clockid, Out::from_mut(&mut now))?; - let next_time = match timespec::add(now, timer_st.next_wake_time.it_interval) { + let next_time = match timespec::add(now, timer_st.next_wake_time.it_interval.clone()) { Some(a) => a, None => timespec::default(), };