Skip to content

Commit d85b0db

Browse files
committed
Auto merge of #116461 - ChrisDenton:sleep, r=thomcc
Windows: Support sub-millisecond sleep Use `CreateWaitableTimerExW` with `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION`. Does not work before Windows 10, version 1803 so in that case we fallback to using `Sleep`. I've created a `WaitableTimer` type so it can one day be adapted to also support waiting to an absolute time (which has been talked about). Note though that it currently returns `Err(())` because we can't do anything with the errors other than fallback to the old `Sleep`. Feel free to tell me to do errors properly. It just didn't seem worth constructing an `io::Error` if we're never going to surface it to the user. And it *should* all be infallible anyway unless the OS is too old to support it. Closes #43376
2 parents 42362a0 + 8a96022 commit d85b0db

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/shims/windows/foreign_items.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
272272

273273
this.Sleep(timeout)?;
274274
}
275+
"CreateWaitableTimerExW" => {
276+
let [attributes, name, flags, access] =
277+
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
278+
this.read_pointer(attributes)?;
279+
this.read_pointer(name)?;
280+
this.read_scalar(flags)?.to_u32()?;
281+
this.read_scalar(access)?.to_u32()?;
282+
// Unimplemented. Always return failure.
283+
let not_supported = this.eval_windows("c", "ERROR_NOT_SUPPORTED");
284+
this.set_last_error(not_supported)?;
285+
this.write_null(dest)?;
286+
}
275287

276288
// Synchronization primitives
277289
"AcquireSRWLockExclusive" => {

0 commit comments

Comments
 (0)