mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 23:02:44 +08:00
Fix timer.rs cross-platform compilation
* macOS does not have RUSAGE_THREAD * tv_sec and tv_usec may be i32 instead of i64
This commit is contained in:
parent
a1a8bc3d8d
commit
b5ff175b45
|
@ -3,7 +3,7 @@
|
|||
use std::time::Duration;
|
||||
|
||||
pub const fn timeval_to_duration(val: &libc::timeval) -> Duration {
|
||||
let micros = val.tv_sec * (1E6 as i64) + val.tv_usec;
|
||||
let micros = val.tv_sec as i64 * (1E6 as i64) + val.tv_usec as i64;
|
||||
Duration::from_micros(micros as u64)
|
||||
}
|
||||
|
||||
|
|
|
@ -68,10 +68,10 @@ fn push_timer_ffi(enabled: bool) -> Box<PrintElapsedOnDropFfi> {
|
|||
}
|
||||
|
||||
/// An enumeration of supported libc rusage types used by [`getrusage()`].
|
||||
/// NB: RUSAGE_THREAD is not supported on macOS.
|
||||
enum RUsage {
|
||||
RSelf, // "Self" is a reserved keyword
|
||||
RChildren,
|
||||
RThread,
|
||||
}
|
||||
|
||||
/// A safe wrapper around `libc::getrusage()`
|
||||
|
@ -81,7 +81,6 @@ fn getrusage(resource: RUsage) -> libc::rusage {
|
|||
match resource {
|
||||
RUsage::RSelf => libc::getrusage(libc::RUSAGE_SELF, rusage.as_mut_ptr()),
|
||||
RUsage::RChildren => libc::getrusage(libc::RUSAGE_CHILDREN, rusage.as_mut_ptr()),
|
||||
RUsage::RThread => libc::getrusage(libc::RUSAGE_THREAD, rusage.as_mut_ptr()),
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user