Skip to content

Commit a779c23

Browse files
dvdskjoboet
andcommitted
sleep_until: fixes incorrect assert, improves comments to docs with links
Co-authored-by: joboet <[email protected]>
1 parent 7f65a9d commit a779c23

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

library/std/src/sys/pal/unix/thread.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ impl Thread {
363363
#[cfg(target_vendor = "apple")]
364364
pub fn sleep_until(deadline: crate::time::Instant) {
365365
use core::mem::MaybeUninit;
366-
367366
use super::time::Timespec;
368367

369368
let Timespec { tv_sec, tv_nsec } = deadline.into_inner().into_timespec();
@@ -379,14 +378,14 @@ impl Thread {
379378

380379
loop {
381380
// There are no docs on the mach_wait_until some details can be
382-
// learned from the `Apple OSS Distributions` xnu source code.
383-
// Specifically: xnu/osfmk/clock.h commit 94d3b45 on Github
381+
// learned from the XNU source code:
382+
// https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/kern/clock.c#L1507-L1543
384383
let ret = mach_wait_until(ticks);
385-
if ret != KERN_ABORTED {
384+
if ret == KERN_SUCCESS {
386385
break;
387386
}
387+
assert_eq!(KERN_ABORTED, "mach_wait_until returned error, code: {ret}");
388388
}
389-
assert_eq!(ret, KERN_SUCCESS);
390389
}
391390
}
392391

@@ -405,13 +404,13 @@ impl Thread {
405404
}
406405
}
407406

408-
// these come from the `Apple OSS Distributions` xnu source code.
409-
// Specifically: xnu/osfmk/mach/kern_return.h commit 94d3b45 on Github
407+
// See https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/mach/kern_return.h
410408
#[cfg(target_vendor = "apple")]
411409
const KERN_SUCCESS: libc::c_int = 0;
412410
#[cfg(target_vendor = "apple")]
413411
const KERN_ABORTED: libc::c_int = 14;
414412

413+
// See https://github.com/apple-oss-distributions/xnu/blob/94d3b452840153a99b38a3a9659680b2a006908e/osfmk/mach/mach_time.h
415414
#[cfg(target_vendor = "apple")]
416415
#[repr(C)]
417416
struct mach_timebase_info_type {

0 commit comments

Comments
 (0)