[vlc-commits] win32: fix mdate() crashing in test cases

Rémi Denis-Courmont git at videolan.org
Fri May 27 23:27:37 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May 28 00:18:03 2016 +0300| [5daf669c7c5286f54f1afda07c72bdee51c0e1d4] | committer: Rémi Denis-Courmont

win32: fix mdate() crashing in test cases

Test cases do not call vlc_threads_setup(). Some of them still need a
working clock. This fixes at least the timer test.

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

 src/win32/thread.c |   42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/src/win32/thread.c b/src/win32/thread.c
index 0f8ef5d..1995556 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -646,20 +646,6 @@ void vlc_control_cancel (int cmd, ...)
 }
 
 /*** Clock ***/
-static CRITICAL_SECTION clock_lock;
-
-static mtime_t mdate_giveup (void)
-{
-    abort ();
-}
-
-static mtime_t (*mdate_selected) (void) = mdate_giveup;
-
-mtime_t mdate (void)
-{
-    return mdate_selected ();
-}
-
 static union
 {
 #if (_WIN32_WINNT < 0x0601)
@@ -753,6 +739,30 @@ static mtime_t mdate_wall (void)
     return s.QuadPart / (10000000 / CLOCK_FREQ);
 }
 
+static CRITICAL_SECTION clock_lock;
+static bool clock_used_early = false;
+
+static mtime_t mdate_default(void)
+{
+    EnterCriticalSection(&clock_lock);
+    if (!clock_used_early)
+    {
+        if (!QueryPerformanceFrequency(&clk.perf.freq))
+            abort();
+        clock_used_early = true;
+    }
+    LeaveCriticalSection(&clock_lock);
+
+    return mdate_perf();
+}
+
+static mtime_t (*mdate_selected) (void) = mdate_default;
+
+mtime_t mdate (void)
+{
+    return mdate_selected ();
+}
+
 #undef mwait
 void mwait (mtime_t deadline)
 {
@@ -778,12 +788,14 @@ void msleep (mtime_t delay)
 static void SelectClockSource (vlc_object_t *obj)
 {
     EnterCriticalSection (&clock_lock);
-    if (mdate_selected != mdate_giveup)
+    if (mdate_selected != mdate_default)
     {
         LeaveCriticalSection (&clock_lock);
         return;
     }
 
+    assert(!clock_used_early);
+
 #if VLC_WINSTORE_APP
     const char *name = "perf";
 #else



More information about the vlc-commits mailing list