summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/unix/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/unix/time.rs')
-rw-r--r--library/std/src/sys/unix/time.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs
index 2daad981b..0f11de8f5 100644
--- a/library/std/src/sys/unix/time.rs
+++ b/library/std/src/sys/unix/time.rs
@@ -9,6 +9,14 @@ pub const UNIX_EPOCH: SystemTime = SystemTime { t: Timespec::zero() };
pub const TIMESPEC_MAX: libc::timespec =
libc::timespec { tv_sec: <libc::time_t>::MAX, tv_nsec: 1_000_000_000 - 1 };
+// This additional constant is only used when calling
+// `libc::pthread_cond_timedwait`.
+#[cfg(target_os = "nto")]
+pub(super) const TIMESPEC_MAX_CAPPED: libc::timespec = libc::timespec {
+ tv_sec: (u64::MAX / NSEC_PER_SEC) as i64,
+ tv_nsec: (u64::MAX % NSEC_PER_SEC) as i64,
+};
+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(0)]
@@ -144,6 +152,20 @@ impl Timespec {
tv_nsec: self.tv_nsec.0.try_into().ok()?,
})
}
+
+ // On QNX Neutrino, the maximum timespec for e.g. pthread_cond_timedwait
+ // is 2^64 nanoseconds
+ #[cfg(target_os = "nto")]
+ pub(super) fn to_timespec_capped(&self) -> Option<libc::timespec> {
+ // Check if timeout in nanoseconds would fit into an u64
+ if (self.tv_nsec.0 as u64)
+ .checked_add((self.tv_sec as u64).checked_mul(NSEC_PER_SEC)?)
+ .is_none()
+ {
+ return None;
+ }
+ self.to_timespec()
+ }
}
impl From<libc::timespec> for Timespec {