X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=compat%2Fw32pthreads.h;h=6405e72b64f70b15e284c19734c26361846e95b9;hb=6ad61e30a16d338eab23b649365813fb150066ef;hp=21acfd2ba1a949ce7e47bc65572ca0eb10b40865;hpb=64425e005edf3bdd77c34c078c3e74ab5ecef557;p=ffmpeg diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h index 21acfd2ba1a..6405e72b64f 100644 --- a/compat/w32pthreads.h +++ b/compat/w32pthreads.h @@ -38,11 +38,13 @@ #define WIN32_LEAN_AND_MEAN #include #include +#include #include "libavutil/attributes.h" #include "libavutil/common.h" #include "libavutil/internal.h" #include "libavutil/mem.h" +#include "libavutil/time.h" typedef struct pthread_t { void *handle; @@ -61,6 +63,9 @@ typedef CONDITION_VARIABLE pthread_cond_t; #define InitializeCriticalSection(x) InitializeCriticalSectionEx(x, 0, 0) #define WaitForSingleObject(a, b) WaitForSingleObjectEx(a, b, FALSE) +#define PTHREAD_CANCEL_ENABLE 1 +#define PTHREAD_CANCEL_DISABLE 0 + static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg) { pthread_t *h = (pthread_t*)arg; @@ -156,10 +161,31 @@ static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex return 0; } +static 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; + DWORD t = av_clip64(abs_milli - av_gettime() / 1000, 0, UINT32_MAX); + + if (!SleepConditionVariableSRW(cond, mutex, t, 0)) { + DWORD err = GetLastError(); + if (err == ERROR_TIMEOUT) + return ETIMEDOUT; + else + return EINVAL; + } + return 0; +} + static inline int pthread_cond_signal(pthread_cond_t *cond) { WakeConditionVariable(cond); return 0; } +static inline int pthread_setcancelstate(int state, int *oldstate) +{ + return 0; +} + #endif /* COMPAT_W32PTHREADS_H */