diff options
| author | Florian Bartels <Florian.Bartels@elektrobit.com> | 2023-01-10 10:44:05 +0100 |
|---|---|---|
| committer | Florian Bartels <Florian.Bartels@elektrobit.com> | 2023-02-28 15:59:47 +0100 |
| commit | 3ce2cd059f8f7c69d9e1fe26b95cec2bfd3c98a7 (patch) | |
| tree | d5944496239e8b36be6d55fac7c285a6a12a3e48 /library/std/src/sys/unix/time.rs | |
| parent | 8f41570e91fcbad2f55800f2edcdea67c3389dc7 (diff) | |
| download | rust-3ce2cd059f8f7c69d9e1fe26b95cec2bfd3c98a7.tar.gz rust-3ce2cd059f8f7c69d9e1fe26b95cec2bfd3c98a7.zip | |
Add QNX Neutrino support to libstd
Co-authored-by: gh-tr <troach@qnx.com>
Diffstat (limited to 'library/std/src/sys/unix/time.rs')
| -rw-r--r-- | library/std/src/sys/unix/time.rs | 22 |
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 2daad981b73..0f11de8f5b8 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 { |
