X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fthread.h;h=be5c4b1340e7ad7b1bef227a44b78af44809c227;hb=bd96c54fe4819b3ca9a975e2083d67f4443c559b;hp=309414aa7dd824ce100b54015542921911e10ef1;hpb=980af9a88cfd743d71fad67e7dd905231ea0a4f7;p=ffmpeg diff --git a/libavutil/thread.h b/libavutil/thread.h index 309414aa7dd..be5c4b1340e 100644 --- a/libavutil/thread.h +++ b/libavutil/thread.h @@ -33,16 +33,19 @@ #include "log.h" +#define ASSERT_PTHREAD_ABORT(func, ret) do { \ + char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \ + av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \ + " failed with error: %s\n", \ + av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \ + AVERROR(ret))); \ + abort(); \ +} while (0) + #define ASSERT_PTHREAD_NORET(func, ...) do { \ int ret = func(__VA_ARGS__); \ - if (ret) { \ - char errbuf[AV_ERROR_MAX_STRING_SIZE] = ""; \ - av_log(NULL, AV_LOG_FATAL, AV_STRINGIFY(func) \ - " failed with error: %s\n", \ - av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, \ - AVERROR(ret))); \ - abort(); \ - } \ + if (ret) \ + ASSERT_PTHREAD_ABORT(func, ret); \ } while (0) #define ASSERT_PTHREAD(func, ...) do { \ @@ -109,6 +112,15 @@ static inline int strict_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t ASSERT_PTHREAD(pthread_cond_wait, cond, mutex); } +static inline int strict_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) +{ + int ret = pthread_cond_timedwait(cond, mutex, abstime); + if (ret && ret != ETIMEDOUT) + ASSERT_PTHREAD_ABORT(pthread_cond_timedwait, ret); + return ret; +} + static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { ASSERT_PTHREAD(pthread_once, once_control, init_routine); @@ -124,6 +136,7 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #define pthread_cond_signal strict_pthread_cond_signal #define pthread_cond_broadcast strict_pthread_cond_broadcast #define pthread_cond_wait strict_pthread_cond_wait +#define pthread_cond_timedwait strict_pthread_cond_timedwait #define pthread_once strict_pthread_once #endif @@ -134,6 +147,7 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #endif #define AVMutex pthread_mutex_t +#define AV_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #define ff_mutex_init pthread_mutex_init #define ff_mutex_lock pthread_mutex_lock @@ -148,6 +162,7 @@ static inline int strict_pthread_once(pthread_once_t *once_control, void (*init_ #else #define AVMutex char +#define AV_MUTEX_INITIALIZER 0 static inline int ff_mutex_init(AVMutex *mutex, const void *attr){ return 0; } static inline int ff_mutex_lock(AVMutex *mutex){ return 0; }