Huw Davies : wineoss: Introduce a helper to retrieve the time.

Alexandre Julliard julliard at winehq.org
Mon May 2 16:02:08 CDT 2022


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

Author: Huw Davies <huw at codeweavers.com>
Date:   Fri Apr 29 08:29:55 2022 +0100

wineoss: Introduce a helper to retrieve the time.

The motivation is that this will need to be called from a
non-Win32 thread and so shouldn't use the Win32 API.  An
added benefit is that it will eliminate the 16ms jitter
associated with GetTickCount().

Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wineoss.drv/ossmidi.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/dlls/wineoss.drv/ossmidi.c b/dlls/wineoss.drv/ossmidi.c
index 1695f1d2f7b..9c8ca8a8f39 100644
--- a/dlls/wineoss.drv/ossmidi.c
+++ b/dlls/wineoss.drv/ossmidi.c
@@ -30,6 +30,8 @@
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdint.h>
+#include <time.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
@@ -155,6 +157,18 @@ static void in_buffer_unlock(void)
     pthread_mutex_unlock(&in_buffer_mutex);
 }
 
+static uint64_t get_time_msec(void)
+{
+    struct timespec now = {0, 0};
+
+#ifdef CLOCK_MONOTONIC_RAW
+    if (!clock_gettime(CLOCK_MONOTONIC_RAW, &now))
+        return (uint64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
+#endif
+    clock_gettime(CLOCK_MONOTONIC, &now);
+    return (uint64_t)now.tv_sec * 1000 + now.tv_nsec / 1000000;
+}
+
 /*
  * notify buffer: The notification ring buffer is implemented so that
  * there is always at least one unused sentinel before the current
@@ -1304,7 +1318,7 @@ NTSTATUS midi_handle_data(void *args)
     struct midi_handle_data_params *params = args;
     unsigned char *buffer = params->buffer;
     unsigned int len = params->len;
-    unsigned int time = NtGetTickCount(), i;
+    unsigned int time = get_time_msec(), i;
     struct midi_src *src;
     unsigned char value;
     WORD dev_id;
@@ -1415,7 +1429,7 @@ static UINT midi_in_start(WORD dev_id)
     if (src->state == -1) return MIDIERR_NODEVICE;
 
     src->state = 1;
-    src->startTime = NtGetTickCount();
+    src->startTime = get_time_msec();
     return MMSYSERR_NOERROR;
 }
 
@@ -1435,7 +1449,7 @@ static UINT midi_in_stop(WORD dev_id)
 
 static UINT midi_in_reset(WORD dev_id, struct notify_context *notify)
 {
-    UINT cur_time = NtGetTickCount();
+    UINT cur_time = get_time_msec();
     UINT err = MMSYSERR_NOERROR;
     struct midi_src *src;
     MIDIHDR *hdr;




More information about the wine-cvs mailing list