[vlc-devel] [PATCH 2/3] win32: unfactorize the code for sleep and WaitForMultipleObjects

Steve Lhomme robux4 at videolabs.io
Mon May 23 17:28:10 CEST 2016


---
 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 c711211..c4efd57 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -73,27 +73,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;
@@ -108,7 +87,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);
@@ -125,7 +103,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;
 }
 
-- 
2.7.2.windows.1



More information about the vlc-devel mailing list