Skip to content
Snippets Groups Projects

win32: simplify the clock selection on startup

Merged Steve Lhomme requested to merge robUx4/vlc:win32-startup-clock into master
All threads resolved!
1 file
+ 1
2
Compare changes
  • Side-by-side
  • Inline
  • It relies on clk.perf.freq.QuadPart which is uninitialized and unknown until
    SelectClockSource() is called. So it calls vlc_threads_setup() each time until
    vlc_threads_setup() is called with the libvlc instance.
    
    Except vlc_threads_setup(NULL) will crash on the
    var_InheritBool(vlc, "high-priority") call.
    
    Usable candidates at startup are:
    * mdate_interrupt which is a counter in 100 ns, not a wall clock
    * mdate_tick which is a counter in 1 ms, not a wall clock
    * mdate_perf_100ns which is a clock in 100 ns but we don't know if the system
    uses that resolution
    * mdate_wall which is a clock in 100 ns resolution (slowest)
    
    mdate_wall gives the better results and should provide a safe transition with
    mdate_perf/mdate_perf_100ns values.
+ 11
31
@@ -43,6 +43,10 @@
#include <time.h>
#include <vlc_atomic.h>
#ifndef NTDDI_WIN10_RS3
#define NTDDI_WIN10_RS3 0x0A000004
#endif
/*** Static mutex and condition variable ***/
static SRWLOCK super_lock = SRWLOCK_INIT;
@@ -526,7 +530,7 @@ static vlc_tick_t mdate_interrupt (void)
/* hundreds of nanoseconds */
static_assert ((10000000 % CLOCK_FREQ) == 0, "Broken frequencies ratio");
return ts / (10000000 / CLOCK_FREQ);
return VLC_TICK_FROM_MSFTIME(ts);
}
static vlc_tick_t mdate_tick (void)
@@ -577,13 +581,7 @@ static vlc_tick_t mdate_wall (void)
return VLC_TICK_FROM_MSFTIME(s.QuadPart);
}
static vlc_tick_t mdate_default(void)
{
vlc_threads_setup(NULL);
return mdate_perf();
}
static vlc_tick_t (*mdate_selected) (void) = mdate_default;
static vlc_tick_t (*mdate_selected) (void) = mdate_wall;
vlc_tick_t vlc_tick_now (void)
{
@@ -631,16 +629,10 @@ void (vlc_tick_sleep)(vlc_tick_t delay)
vlc_tick_wait (vlc_tick_now () + delay);
}
static BOOL SelectClockSource(vlc_object_t *obj)
static void SelectClockSource(libvlc_int_t *obj)
{
const char *name = "perf";
char *str = NULL;
if (obj != NULL)
{
str = var_InheritString(obj, "clock-source");
if (str != NULL)
name = str;
}
char *str = var_InheritString(obj, "clock-source");
const char *name = str != NULL ? str : "perf";
if (!strcmp (name, "interrupt"))
{
msg_Dbg (obj, "using interrupt time as clock source");
@@ -676,7 +668,6 @@ static BOOL SelectClockSource(vlc_object_t *obj)
abort ();
}
free (str);
return TRUE;
}
@@ -692,22 +683,12 @@ unsigned vlc_GetCPUCount (void)
/*** Initialization ***/
static SRWLOCK setup_lock = SRWLOCK_INIT; /* FIXME: use INIT_ONCE */
void vlc_threads_setup(libvlc_int_t *vlc)
{
AcquireSRWLockExclusive(&setup_lock);
if (mdate_selected != mdate_default)
{
ReleaseSRWLockExclusive(&setup_lock);
return;
}
if (!SelectClockSource((vlc != NULL) ? VLC_OBJECT(vlc) : NULL))
abort();
assert(mdate_selected != mdate_default);
SelectClockSource(vlc);
#ifndef VLC_WINSTORE_APP
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) || NTDDI_VERSION >= NTDDI_WIN10_RS3
/* Raise default priority of the current process */
#ifndef ABOVE_NORMAL_PRIORITY_CLASS
# define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
@@ -721,7 +702,6 @@ void vlc_threads_setup(libvlc_int_t *vlc)
msg_Dbg(vlc, "could not raise process priority");
}
#endif
ReleaseSRWLockExclusive(&setup_lock);
}
#define LOOKUP(s) (((s##_) = (void *)GetProcAddress(h, #s)) != NULL)
Loading