Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60
From: Jinoh Kang jinoh.kang.kr@gmail.com
--- include/winnt.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
diff --git a/include/winnt.h b/include/winnt.h index e8a47fec963..f0f13afa508 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -7195,6 +7195,19 @@ static FORCEINLINE void WriteNoFence( LONG volatile *dest, LONG value ) __WINE_STORE32_NO_FENCE( (int volatile *)dest, value ); }
+static FORCEINLINE void WriteNoFence64( LONG64 volatile *dest, LONG64 value ) +{ +#if defined(__i386__) && _MSC_VER < 1700 + __asm { + mov eax, dest + fild value + fistp qword ptr [eax] + } +#else + __WINE_STORE64_NO_FENCE( (__int64 volatile *)dest, value ); +#endif +} + #elif defined(__GNUC__)
static FORCEINLINE BOOLEAN WINAPI BitScanForward(DWORD *index, DWORD mask) @@ -7411,6 +7424,15 @@ static FORCEINLINE void WriteNoFence( LONG volatile *dest, LONG value ) __WINE_ATOMIC_STORE_RELAXED( dest, &value ); }
+static FORCEINLINE void WriteNoFence64( LONG64 volatile *dest, LONG64 value ) +{ +#ifdef __i386__ + __asm__ __volatile__( "fildq %1\n\tfistpq %0" : "=m" (*dest) : "m" (value) : "memory", "st" ); +#else + __WINE_ATOMIC_STORE_RELAXED( dest, &value ); +#endif +} + static FORCEINLINE DECLSPEC_NORETURN void __fastfail(unsigned int code) { #if defined(__x86_64__) || defined(__i386__)
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/libs/fluidsynth/glib.c b/libs/fluidsynth/glib.c index cd938a4fb6b..a399850c915 100644 --- a/libs/fluidsynth/glib.c +++ b/libs/fluidsynth/glib.c @@ -40,10 +40,14 @@ int g_snprintf( char *buffer, size_t size, const char *format, ... )
double g_get_monotonic_time(void) { - static LARGE_INTEGER frequency = {0}; - LARGE_INTEGER counter; + static volatile LONG64 freq_cache; + LARGE_INTEGER counter, frequency;
- if (!frequency.QuadPart) QueryPerformanceFrequency( &frequency ); + if (!(frequency.QuadPart = ReadNoFence64( &freq_cache ))) + { + QueryPerformanceFrequency( &frequency ); + WriteNoFence64( &freq_cache, frequency.QuadPart ); + } QueryPerformanceCounter( &counter );
return counter.QuadPart * 1000000.0 / frequency.QuadPart; /* time in micros */
Fwiw I don't know if it's better to hardcode it but as far as I know the frequency is always the same constant. I think Microsoft attempted to change it on some Windows 10 versions, when they introduced QPC optimisations with rdtsc and the hyperv shared memory page, but then rolled back to the same old constant. There's probably too many applications out there which hradcoded it already.