[vlc-commits] win32: use futex-based sleep (Windows 8+)

Rémi Denis-Courmont git at videolan.org
Wed Jun 1 21:57:09 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jun  1 00:31:33 2016 +0300| [beeefe7500ad32fb75620d20c2e808e83281c649] | committer: Rémi Denis-Courmont

win32: use futex-based sleep (Windows 8+)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=beeefe7500ad32fb75620d20c2e808e83281c649
---

 src/misc/threads.c |    2 ++
 src/win32/thread.c |   36 ++++++------------------------------
 2 files changed, 8 insertions(+), 30 deletions(-)

diff --git a/src/misc/threads.c b/src/misc/threads.c
index eec58a3..1d99bf9 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -71,6 +71,8 @@ static void vlc_cancel_addr_finish(void *addr)
 }
 
 # if defined (_WIN32) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
+/* Cannot define OS version-dependent stuff in public headers */
+#  define LIBVLC_NEED_SLEEP
 #  define LIBVLC_NEED_SEMAPHORE
 # endif
 #endif
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 90b9869..1880cf6 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -103,31 +103,6 @@ static DWORD vlc_WaitForSingleObject (HANDLE handle, DWORD delay)
     return vlc_WaitForMultipleObjects (1, &handle, delay);
 }
 
-static DWORD vlc_Sleep (DWORD 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;
-}
-
 
 /*** Mutexes ***/
 void vlc_mutex_init( vlc_mutex_t *p_mutex )
@@ -864,8 +839,8 @@ mtime_t mdate (void)
     return mdate_selected ();
 }
 
-#undef mwait
-void mwait (mtime_t deadline)
+#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
+void (mwait)(mtime_t deadline)
 {
     mtime_t delay;
 
@@ -875,16 +850,17 @@ void mwait (mtime_t deadline)
         delay = (delay + 999) / 1000;
         if (unlikely(delay > 0x7fffffff))
             delay = 0x7fffffff;
-        vlc_Sleep (delay);
+
+        SleepEx(delay, TRUE);
         vlc_testcancel();
     }
 }
 
-#undef msleep
-void msleep (mtime_t delay)
+void (msleep)(mtime_t delay)
 {
     mwait (mdate () + delay);
 }
+#endif
 
 static void SelectClockSource (vlc_object_t *obj)
 {



More information about the vlc-commits mailing list