vlc | branch: master | Steve Lhomme <[email protected]> | Mon May 23 17:28:10 2016 +0200| [467a4dac48fcf444acaea3f8306ec3692450c4be] | committer: Rémi Denis-Courmont
win32: unfactorize the code for sleep and WaitForMultipleObjects Signed-off-by: Rémi Denis-Courmont <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=467a4dac48fcf444acaea3f8306ec3692450c4be --- src/win32/thread.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/win32/thread.c b/src/win32/thread.c index 49e533e..90b9869 100644 --- a/src/win32/thread.c +++ b/src/win32/thread.c @@ -75,27 +75,6 @@ static DWORD vlc_WaitForMultipleObjects (DWORD count, const HANDLE *handles, DWORD delay) { DWORD ret; - if (count == 0) - { -#if !IS_INTERRUPTIBLE - do { - DWORD new_delay = 50; - if (new_delay > delay) - new_delay = delay; - ret = SleepEx (new_delay, TRUE); - if (delay != INFINITE) - delay -= new_delay; - if (isCancelled()) - ret = WAIT_IO_COMPLETION; - } while (delay && ret == 0); -#else - ret = SleepEx (delay, TRUE); -#endif - - if (ret == 0) - ret = WAIT_TIMEOUT; - } - else { #if !IS_INTERRUPTIBLE do { DWORD new_delay = 50; @@ -110,7 +89,6 @@ static DWORD vlc_WaitForMultipleObjects (DWORD count, const HANDLE *handles, #else ret = WaitForMultipleObjectsEx (count, handles, FALSE, delay, TRUE); #endif - } /* We do not abandon objects... this would be a bug */ assert (ret < WAIT_ABANDONED_0 || WAIT_ABANDONED_0 + count - 1 < ret); @@ -127,7 +105,26 @@ static DWORD vlc_WaitForSingleObject (HANDLE handle, DWORD delay) static DWORD vlc_Sleep (DWORD delay) { - DWORD ret = vlc_WaitForMultipleObjects (0, NULL, delay); + DWORD ret; +#if !IS_INTERRUPTIBLE + do { + DWORD new_delay = 50; + if (new_delay > delay) + new_delay = delay; + ret = SleepEx (new_delay, TRUE); + if (delay != INFINITE) + delay -= new_delay; + if (isCancelled()) + ret = WAIT_IO_COMPLETION; + } while (delay && ret == 0); +#else + ret = SleepEx (delay, TRUE); +#endif + + if (unlikely(ret == WAIT_FAILED)) + abort (); /* We are screwed! */ + if (ret == 0) + ret = WAIT_TIMEOUT; return (ret != WAIT_TIMEOUT) ? ret : 0; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
