Zebediah Figura : quartz: Use the performance counter for the system clock.

Alexandre Julliard julliard at winehq.org
Thu Oct 21 16:04:17 CDT 2021


Module: wine
Branch: master
Commit: bf5b35f19b841e6352c32ca7c6671d9172636871
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bf5b35f19b841e6352c32ca7c6671d9172636871

Author: Zebediah Figura <zfigura at codeweavers.com>
Date:   Thu Oct 21 12:41:11 2021 -0500

quartz: Use the performance counter for the system clock.

Native probably uses timeGetTime() as a source. That doesn't actually match the
performance counter on Windows, but it does on Wine, and accessing the counter
directly is slightly more efficient anyway.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51684
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/quartz/systemclock.c       | 14 ++++++++++++--
 dlls/quartz/tests/Makefile.in   |  2 +-
 dlls/quartz/tests/systemclock.c |  9 +--------
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/dlls/quartz/systemclock.c b/dlls/quartz/systemclock.c
index cebe4846f04..56ad217c76a 100644
--- a/dlls/quartz/systemclock.c
+++ b/dlls/quartz/systemclock.c
@@ -44,6 +44,7 @@ struct system_clock
 
     BOOL thread_created, thread_stopped;
     HANDLE thread;
+    LARGE_INTEGER frequency;
     REFERENCE_TIME last_time;
     CRITICAL_SECTION cs;
     CONDITION_VARIABLE cv;
@@ -51,6 +52,14 @@ struct system_clock
     struct list sinks;
 };
 
+static REFERENCE_TIME get_current_time(const struct system_clock *clock)
+{
+    LARGE_INTEGER time;
+
+    QueryPerformanceCounter(&time);
+    return (time.QuadPart * 1000) / clock->frequency.QuadPart * 10000;
+}
+
 static inline struct system_clock *impl_from_IUnknown(IUnknown *iface)
 {
     return CONTAINING_RECORD(iface, struct system_clock, IUnknown_inner);
@@ -145,7 +154,7 @@ static DWORD WINAPI SystemClockAdviseThread(void *param)
 
         EnterCriticalSection(&clock->cs);
 
-        current_time = GetTickCount64() * 10000;
+        current_time = get_current_time(clock);
 
         LIST_FOR_EACH_ENTRY_SAFE(sink, cursor, &clock->sinks, struct advise_sink, entry)
         {
@@ -240,7 +249,7 @@ static HRESULT WINAPI SystemClockImpl_GetTime(IReferenceClock *iface, REFERENCE_
         return E_POINTER;
     }
 
-    ret = GetTickCount64() * 10000;
+    ret = get_current_time(clock);
 
     EnterCriticalSection(&clock->cs);
 
@@ -336,6 +345,7 @@ HRESULT system_clock_create(IUnknown *outer, IUnknown **out)
     list_init(&object->sinks);
     InitializeCriticalSection(&object->cs);
     object->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SystemClockImpl.cs");
+    QueryPerformanceFrequency(&object->frequency);
 
     TRACE("Created system clock %p.\n", object);
     *out = &object->IUnknown_inner;
diff --git a/dlls/quartz/tests/Makefile.in b/dlls/quartz/tests/Makefile.in
index b4a372d4d3e..423abc78ef6 100644
--- a/dlls/quartz/tests/Makefile.in
+++ b/dlls/quartz/tests/Makefile.in
@@ -1,5 +1,5 @@
 TESTDLL   = quartz.dll
-IMPORTS   = strmbase advapi32 d3d9 dsound msdmo msvfw32 ole32 oleaut32 user32 uuid
+IMPORTS   = strmbase advapi32 d3d9 dsound msdmo msvfw32 ole32 oleaut32 user32 uuid winmm
 
 C_SRCS = \
 	acmwrapper.c \
diff --git a/dlls/quartz/tests/systemclock.c b/dlls/quartz/tests/systemclock.c
index be5472ed6e1..3b39d2aadb4 100644
--- a/dlls/quartz/tests/systemclock.c
+++ b/dlls/quartz/tests/systemclock.c
@@ -22,8 +22,6 @@
 #include "dshow.h"
 #include "wine/test.h"
 
-static ULONGLONG (WINAPI *pGetTickCount64)(void);
-
 static IReferenceClock *create_system_clock(void)
 {
     IReferenceClock *clock = NULL;
@@ -178,10 +176,7 @@ static void test_get_time(void)
     ok(time1 % 10000 == 0, "Expected no less than 1ms coarseness, but got time %s.\n",
             wine_dbgstr_longlong(time1));
 
-    if (pGetTickCount64)
-        ticks = pGetTickCount64() * 10000;
-    else
-        ticks = (REFERENCE_TIME)GetTickCount() * 10000;
+    ticks = (REFERENCE_TIME)timeGetTime() * 10000;
 
     hr = IReferenceClock_GetTime(clock, &time2);
     ok(hr == (time2 == time1 ? S_FALSE : S_OK), "Got hr %#x.\n", hr);
@@ -291,8 +286,6 @@ START_TEST(systemclock)
 {
     CoInitialize(NULL);
 
-    pGetTickCount64 = (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetTickCount64");
-
     test_interfaces();
     test_aggregation();
     test_get_time();




More information about the wine-cvs mailing list