Commit 5daf669c authored by Rémi Denis-Courmont's avatar 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.
parent f2f32ee7
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment