Skip to content

Commit f1bd09d

Browse files
authored
Rollup merge of #157867 - devnexen:condvar_xous_timeout_fix, r=clarfonthey
std: sys: xous: clamp condvar wait_timeout instead of truncating dur.as_millis() (u128) was cast straight to usize, so on 32-bit xous any timeout over ~49 days truncated, and an exact multiple of 2^32 ms became 0 and then 1ms via the "don't wait forever" guard. Saturate the conversion, matching sys/sync/thread_parking/xous.rs.
2 parents c75a9fa + 5f65b74 commit f1bd09d

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

  • library/std/src/sys/sync/condvar

library/std/src/sys/sync/condvar/xous.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ impl Condvar {
124124
}
125125

126126
pub unsafe fn wait_timeout(&self, mutex: &Mutex, dur: Duration) -> bool {
127-
let mut millis = dur.as_millis() as usize;
128-
// Ensure we don't wait for 0 ms, which would cause us to wait forever
129-
if millis == 0 {
130-
millis = 1;
131-
}
127+
// A value of zero indicates an indefinite wait, so clamp the number of
128+
// milliseconds to the representable range and avoid waiting forever.
129+
let millis = usize::max(dur.as_millis().try_into().unwrap_or(usize::MAX), 1);
132130
self.wait_ms(mutex, millis)
133131
}
134132
}

0 commit comments

Comments
 (0)