Skip to content

Commit 0079a36

Browse files
committed
Added more platforms
1 parent 6cd32ef commit 0079a36

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/time.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ impl ClockId {
2121
}
2222

2323
/// Returns `ClockId` of a `pid` CPU-time clock
24-
#[cfg(target_os = "linux")]
24+
#[cfg(any(
25+
target_os = "freebsd",
26+
target_os = "dragonfly",
27+
target_os = "linux",
28+
target_os = "android",
29+
target_os = "emscripten",
30+
))]
2531
pub fn pid_cpu_clock_id(pid: Pid) -> Result<Self> {
2632
clock_getcpuclockid(pid)
2733
}
@@ -229,7 +235,13 @@ pub fn clock_settime(clock_id: ClockId, timespec: TimeSpec) -> Result<()> {
229235

230236
/// Get the clock id of the specified process id, (see
231237
/// [clock_getcpuclockid(3)](https://www.man7.org/linux/man-pages/man3/clock_getcpuclockid.3.html)).
232-
#[cfg(target_os = "linux")]
238+
#[cfg(any(
239+
target_os = "freebsd",
240+
target_os = "dragonfly",
241+
target_os = "linux",
242+
target_os = "android",
243+
target_os = "emscripten",
244+
))]
233245
pub fn clock_getcpuclockid(pid: Pid) -> Result<ClockId> {
234246
let mut clk_id: MaybeUninit<libc::clockid_t> = MaybeUninit::uninit();
235247
let ret = unsafe { libc::clock_getcpuclockid(pid.into(), clk_id.as_mut_ptr()) };

test/test_time.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#[cfg(target_os = "linux")]
1+
#[cfg(any(
2+
target_os = "freebsd",
3+
target_os = "dragonfly",
4+
target_os = "linux",
5+
target_os = "android",
6+
target_os = "emscripten",
7+
))]
28
use nix::time::clock_getcpuclockid;
39
use nix::time::{clock_getres, clock_gettime, ClockId};
410

@@ -12,7 +18,13 @@ pub fn test_clock_gettime() {
1218
assert!(clock_gettime(ClockId::CLOCK_REALTIME).is_ok());
1319
}
1420

15-
#[cfg(target_os = "linux")]
21+
#[cfg(any(
22+
target_os = "freebsd",
23+
target_os = "dragonfly",
24+
target_os = "linux",
25+
target_os = "android",
26+
target_os = "emscripten",
27+
))]
1628
#[test]
1729
pub fn test_clock_getcpuclockid() {
1830
let clock_id = clock_getcpuclockid(nix::unistd::Pid::this()).unwrap();
@@ -29,7 +41,13 @@ pub fn test_clock_id_now() {
2941
assert!(ClockId::CLOCK_REALTIME.now().is_ok());
3042
}
3143

32-
#[cfg(target_os = "linux")]
44+
#[cfg(any(
45+
target_os = "freebsd",
46+
target_os = "dragonfly",
47+
target_os = "linux",
48+
target_os = "android",
49+
target_os = "emscripten",
50+
))]
3351
#[test]
3452
pub fn test_clock_id_pid_cpu_clock_id() {
3553
assert!(ClockId::pid_cpu_clock_id(nix::unistd::Pid::this())

0 commit comments

Comments
 (0)