[FFmpeg-devel] [PATCH] avutil/thread: fix strict_pthread_cond_timedwait

Marton Balint cus at passwd.hu
Sun Jan 26 00:29:00 EET 2020



On Wed, 22 Jan 2020, Marton Balint wrote:

> Timeout error was assumed to be fatal which it is not.

Applied.

Regards,
Marton

>
> Signed-off-by: Marton Balint <cus at passwd.hu>
> ---
> libavutil/thread.h | 24 +++++++++++++++---------
> 1 file changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/libavutil/thread.h b/libavutil/thread.h
> index 65b97ef303..be5c4b1340 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 {                                  \
> @@ -112,7 +115,10 @@ static inline int strict_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t
> static inline int strict_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
>                                                 const struct timespec *abstime)
> {
> -    ASSERT_PTHREAD(pthread_cond_timedwait, cond, mutex, 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))
> -- 
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list