winpr/thread: fix SwitchToThread

On some operating systems sched_yield is a stub returning returning -1.
In that case use usleep which should at least trigger a context switch
if any thread is waiting.
This commit is contained in:
Norbert Federa 2016-06-02 15:38:57 +02:00
parent e718fb324b
commit 458f606934

View File

@ -706,7 +706,14 @@ DWORD SuspendThread(HANDLE hThread)
BOOL SwitchToThread(VOID)
{
return (sched_yield() == 0);
/**
* Note: on some operating systems sched_yield is a stub returning -1.
* usleep should at least trigger a context switch if any thread is waiting.
*/
if (!sched_yield())
usleep(1);
return TRUE;
}
BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode)