Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- sched_yield() causes the thread to relinquish the CPU, but only to a thread at the same priority level. If there is no other runnable thread with the same priority, the caller gets rescheduled right away. A number of games (Starcraft 2 and Shadow of the Tomb Raider are two that I have explicitly mentioned in my notes) in particular call Sleep(0) or NtYieldExecution() while on the main menu, with the idea of sleeping for a while before getting rescheduled. sched_yield() doesn't do what we want. usleep() does. FWIW the man page for sched_yield() does mention that it's intended to be used with realtime scheduling policies and calling it with processes using the default SCHED_OTHER policy (like Wine) is a bad idea.
Windows doesn't give any particular guarantee about minimal sleep duration. MSDN just says that it yields the CPU for "the remainder of its time slice". Also Sleep(0) changed a bit after Windows XP, going from relinquishing the time slice to "other threads of equal priority" to "any other thread", so I think this change makes the function follow more closely current Windows behavior regardless.
configure | 1 - configure.ac | 1 - dlls/ntdll/unix/sync.c | 6 +----- include/config.h.in | 3 --- 4 files changed, 1 insertion(+), 10 deletions(-)
diff --git a/configure b/configure index db2e07679d4..096d750c9cc 100755 --- a/configure +++ b/configure @@ -17916,7 +17916,6 @@ for ac_func in \ prctl \ proc_pidinfo \ readlink \ - sched_yield \ setproctitle \ setprogname \ sigprocmask \ diff --git a/configure.ac b/configure.ac index 6321206b9db..ec65c6abc59 100644 --- a/configure.ac +++ b/configure.ac @@ -2147,7 +2147,6 @@ AC_CHECK_FUNCS(\ prctl \ proc_pidinfo \ readlink \ - sched_yield \ setproctitle \ setprogname \ sigprocmask \ diff --git a/dlls/ntdll/unix/sync.c b/dlls/ntdll/unix/sync.c index 5a5d49bf4bd..1a8c386d3a8 100644 --- a/dlls/ntdll/unix/sync.c +++ b/dlls/ntdll/unix/sync.c @@ -1506,12 +1506,8 @@ NTSTATUS WINAPI NtSignalAndWaitForSingleObject( HANDLE signal, HANDLE wait, */ NTSTATUS WINAPI NtYieldExecution(void) { -#ifdef HAVE_SCHED_YIELD - sched_yield(); + usleep(0); return STATUS_SUCCESS; -#else - return STATUS_NO_YIELD_PERFORMED; -#endif }
diff --git a/include/config.h.in b/include/config.h.in index e27b23f658f..1cffe6ebac9 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -537,9 +537,6 @@ /* Define to 1 if you have the `sched_setaffinity' function. */ #undef HAVE_SCHED_SETAFFINITY
-/* Define to 1 if you have the `sched_yield' function. */ -#undef HAVE_SCHED_YIELD - /* Define to 1 if `cmd' is a member of `scsireq_t'. */ #undef HAVE_SCSIREQ_T_CMD