[PATCH 3/6] 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(a)codeweavers.com> --- 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; -- 2.25.1
Signed-off-by: Andrew Eikum <aeikum(a)codeweavers.com> On Fri, Apr 29, 2022 at 08:29:55AM +0100, Huw Davies wrote:
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(a)codeweavers.com> --- 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; -- 2.25.1
participants (2)
-
Andrew Eikum -
Huw Davies