msr_core/thread.rs
1use std::time::Instant;
2
3pub use std::thread::*;
4
5/// Puts the current thread to sleep for at least until the deadline
6///
7/// The thread may sleep longer than the deadline specified due to scheduling
8/// specifics or platform-dependent functionality. It will never sleep less.
9///
10/// See also: <https://doc.rust-lang.org/std/thread/fn.sleep.html>
11///
12/// TODO: Use [spin-sleep](https://github.com/alexheretic/spin-sleep) depending
13/// on the use case for reliable accuracy to limit the maximum jitter?
14pub fn sleep_until(deadline: Instant) {
15 let now = Instant::now();
16 if now >= deadline {
17 return;
18 }
19 sleep(deadline.duration_since(now));
20}