Skip to content

Commit 07002fb

Browse files
committed
Add fallback for SwitchToThread by using Sleep(0)
1 parent 40b1e40 commit 07002fb

File tree

1 file changed

+11
-0
lines changed
  • library/std/src/sys/windows

1 file changed

+11
-0
lines changed

library/std/src/sys/windows/c.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,17 @@ compat_fn_with_fallback! {
406406
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
407407
FALSE
408408
}
409+
410+
// >= NT 4+
411+
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-switchtothread
412+
pub fn SwitchToThread() -> BOOL {
413+
// A value of zero causes the thread to relinquish the remainder of its time slice to any
414+
// other thread of equal priority that is ready to run. If there are no other threads of
415+
// equal priority ready to run, the function returns immediately, and the thread continues
416+
// execution.
417+
Sleep(0);
418+
TRUE
419+
}
409420
}
410421

411422
compat_fn_lazy! {

0 commit comments

Comments
 (0)