diff --git a/src/header/bits_timespec/mod.rs b/src/header/bits_timespec/mod.rs index cd8539f21a..9bc6a5d5ee 100644 --- a/src/header/bits_timespec/mod.rs +++ b/src/header/bits_timespec/mod.rs @@ -16,7 +16,7 @@ impl timespec { /// similar logic with timeradd #[allow(clippy::should_implement_trait)] // not to confuse std::ops::Add - pub fn add(base: timespec, interval: timespec) -> Option { + pub fn add(base: ×pec, interval: ×pec) -> Option { let delta_sec = base.tv_sec.checked_add(interval.tv_sec)?; let delta_nsec = base.tv_nsec.checked_add(interval.tv_nsec)?; @@ -30,7 +30,7 @@ impl timespec { }) } /// similar logic with timersub - pub fn subtract(later: timespec, earlier: timespec) -> Option { + pub fn subtract(later: ×pec, earlier: ×pec) -> Option { let delta_sec = later.tv_sec.checked_sub(earlier.tv_sec)?; let delta_nsec = later.tv_nsec.checked_sub(earlier.tv_nsec)?; diff --git a/src/header/pthread/mutex.rs b/src/header/pthread/mutex.rs index 9f53257dbf..67c802aeef 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.clone()) { + let relative = match timespec_realtime_to_monotonic(abstime) { Ok(relative) => relative, Err(err) => return e(Err(err)), }; diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 36f02d6ff6..fe0b1b66fe 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -882,15 +882,15 @@ const fn blank_tm() -> tm { } } -pub(crate) fn timespec_realtime_to_monotonic(abstime: timespec) -> Result { +pub(crate) fn timespec_realtime_to_monotonic(abstime: ×pec) -> Result { let mut realtime = timespec::default(); unsafe { clock_gettime(CLOCK_REALTIME, &raw mut realtime) }; let mut monotonic = timespec::default(); unsafe { clock_gettime(CLOCK_MONOTONIC, &raw mut monotonic) }; - let Some(delta) = timespec::subtract(abstime, realtime) else { + let Some(delta) = timespec::subtract(abstime, &realtime) else { return Err(Errno(ETIMEDOUT)); }; - let Some(relative) = timespec::add(monotonic, delta) else { + let Some(relative) = timespec::add(&monotonic, &delta) else { return Err(Errno(ENOMEM)); }; Ok(relative) diff --git a/src/platform/redox/mod.rs b/src/platform/redox/mod.rs index 068b7c1d6b..323bfdbf19 100644 --- a/src/platform/redox/mod.rs +++ b/src/platform/redox/mod.rs @@ -1354,7 +1354,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.clone(), now.clone()).is_none() { + if timespec::subtract(&timer_st.next_wake_time.it_value, &now).is_none() { // error here means the timer is disarmed let _ = timer_update_wake_time(timer_st); } @@ -1366,7 +1366,7 @@ impl Pal for Sys { } else { itimerspec { it_interval: timer_st.next_wake_time.it_interval.clone(), - it_value: timespec::subtract(timer_st.next_wake_time.it_value.clone(), now) + it_value: timespec::subtract(&timer_st.next_wake_time.it_value, &now) .unwrap_or_default(), } }); @@ -1392,7 +1392,7 @@ impl Pal for Sys { if flags & TIMER_ABSTIME == 0 { let mut now = timespec::default(); Self::clock_gettime(timer_st.clockid, Out::from_mut(&mut now))?; - val.it_value = timespec::add(now, val.it_value).ok_or(Errno(EINVAL))?; + val.it_value = timespec::add(&now, &val.it_value).ok_or(Errno(EINVAL))?; } val }; diff --git a/src/platform/redox/timer.rs b/src/platform/redox/timer.rs index 85063fc03b..fccd059cc3 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.clone()) { + let next_time = match timespec::add(&now, &timer_st.next_wake_time.it_interval) { Some(a) => a, None => timespec::default(), }; diff --git a/src/sync/cond.rs b/src/sync/cond.rs index 19f9868a19..fd29aa91b2 100644 --- a/src/sync/cond.rs +++ b/src/sync/cond.rs @@ -73,7 +73,7 @@ impl Cond { let relative = match clock_id { // FUTEX expect monotonic clock CLOCK_MONOTONIC => timeout.clone(), - CLOCK_REALTIME => timespec_realtime_to_monotonic(timeout.clone())?, + CLOCK_REALTIME => timespec_realtime_to_monotonic(timeout)?, _ => return Err(Errno(EINVAL)), }; diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index c93fe05dc9..73b367a3db 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -38,9 +38,7 @@ impl InnerRwLock { let relative = match deadline { // FUTEX expect monotonic clock Some((abstime, CLOCK_MONOTONIC)) => Some(abstime.clone()), - Some((abstime, CLOCK_REALTIME)) => { - Some(timespec_realtime_to_monotonic(abstime.clone())?) - } + Some((abstime, CLOCK_REALTIME)) => Some(timespec_realtime_to_monotonic(abstime)?), None => None, _ => { return Err(Errno(EINVAL)); diff --git a/src/sync/semaphore.rs b/src/sync/semaphore.rs index ce1496188a..8052bfaaa2 100644 --- a/src/sync/semaphore.rs +++ b/src/sync/semaphore.rs @@ -66,7 +66,7 @@ impl Semaphore { let relative = match clock_id { // FUTEX expect monotonic clock CLOCK_MONOTONIC => timeout.clone(), - CLOCK_REALTIME => match timespec_realtime_to_monotonic(timeout.clone()) { + CLOCK_REALTIME => match timespec_realtime_to_monotonic(timeout) { Ok(relative) => relative, Err(_) => return Err(()), },