diff options
author | sfan5 <sfan5@live.de> | 2023-10-17 13:52:54 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-10-20 21:30:51 +0200 |
commit | 9f147496b50e1d281b61e9659401d0abdfc97d3f (patch) | |
tree | c5bf6a5575d2be5d049fea5debf1c0a1d8909b58 /osdep/win32 | |
parent | 9a7291d48ea8ee9c661a7a1f70de1c75cad17336 (diff) | |
download | mpv-9f147496b50e1d281b61e9659401d0abdfc97d3f.tar.bz2 mpv-9f147496b50e1d281b61e9659401d0abdfc97d3f.tar.xz |
Revert "win32/pthread: don't convert time through unrelated timer"
This reverts commit 318b5471a18e464cfcd1f7222da7853b7056f9fc.
While it may work, changing these two functions in violation of their documented
behaviour for the sake of a shortcut is a hack that will spell disaster sooner or later.
This is a partial revert since the commit in question also contained a hidden
bugfix where it swapped the calculation order for time_rel.
Diffstat (limited to 'osdep/win32')
-rw-r--r-- | osdep/win32/pthread.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/osdep/win32/pthread.c b/osdep/win32/pthread.c index 905f1107f7..a178d72253 100644 --- a/osdep/win32/pthread.c +++ b/osdep/win32/pthread.c @@ -23,7 +23,6 @@ #include <assert.h> #include <windows.h> -#include "common/common.h" #include "osdep/timer.h" // mp_{start,end}_hires_timers int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) @@ -96,11 +95,22 @@ int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) { - // mp time is not converted to realtime if internal pthread impl is used - int64_t now = mp_time_ns(); - int64_t time_ns = abstime->tv_sec * UINT64_C(1000000000) + abstime->tv_nsec; - int64_t timeout_ms = (time_ns - now) / INT64_C(1000000); - return cond_wait(cond, mutex, MPCLAMP(timeout_ms, 0, INFINITE)); + // mpv uses mingw's gettimeofday() as time source too. + struct timeval tv; + gettimeofday(&tv, NULL); + DWORD timeout_ms = 0; + if (abstime->tv_sec >= INT64_MAX / 10000) { + timeout_ms = INFINITE; + } else if (abstime->tv_sec >= tv.tv_sec) { + long long msec = (abstime->tv_sec - tv.tv_sec) * 1000LL + + abstime->tv_nsec / 1000LL / 1000LL - tv.tv_usec / 1000LL; + if (msec > INT_MAX) { + timeout_ms = INFINITE; + } else if (msec > 0) { + timeout_ms = msec; + } + } + return cond_wait(cond, mutex, timeout_ms); } int pthread_cond_wait(pthread_cond_t *restrict cond, |