+static av_always_inline int pthread_cond_timedwait(pthread_cond_t *cond,
+ pthread_mutex_t *mutex,
+ const struct timespec *abstime)
+{
+ int64_t abs_milli = abstime->tv_sec * 1000LL + abstime->tv_nsec / 1000000;
+ ULONG t = av_clip64(abs_milli - av_gettime() / 1000, 0, ULONG_MAX);
+
+ __atomic_increment(&cond->wait_count);
+
+ pthread_mutex_unlock(mutex);
+
+ APIRET ret = DosWaitEventSem(cond->event_sem, t);
+
+ __atomic_decrement(&cond->wait_count);
+
+ DosPostEventSem(cond->ack_sem);
+
+ pthread_mutex_lock(mutex);
+
+ return (ret == ERROR_TIMEOUT) ? ETIMEDOUT : 0;
+}
+