Skip to content

Commit 1e776df

Browse files
committed
(lib/sleep_until) mac, check for aborted and comment on docs
1 parent d614da2 commit 1e776df

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,15 @@ impl Thread {
375375
let info = info.assume_init();
376376
let ticks = nanos * (info.denom as u64) / (info.numer as u64);
377377

378-
let ret = mach_wait_until(ticks);
378+
loop {
379+
// There are no docs on the mach_wait_until some details can be
380+
// learned from the `Apple OSS Distributions` xnu source code.
381+
// Specifically: xnu/osfmk/clock.h commit 94d3b45 on Github
382+
let ret = mach_wait_until(ticks);
383+
if ret != KERN_ABORTED {
384+
break;
385+
}
386+
}
379387
assert_eq!(ret, KERN_SUCCESS);
380388
}
381389
}
@@ -395,8 +403,12 @@ impl Thread {
395403
}
396404
}
397405

406+
// these come from the `Apple OSS Distributions` xnu source code.
407+
// Specifically: xnu/osfmk/mach/kern_return.h commit 94d3b45 on Github
398408
#[cfg(target_vendor = "apple")]
399409
const KERN_SUCCESS: libc::c_int = 0;
410+
#[cfg(target_vendor = "apple")]
411+
const KERN_SUCCESS: libc::c_int = 14;
400412

401413
#[cfg(target_vendor = "apple")]
402414
#[repr(C)]

0 commit comments

Comments
 (0)