[FFmpeg-devel] [PATCH] avcodec/utils: use a default lock manager that uses a spinlock

Paul B Mahol onemda at gmail.com
Thu Oct 17 15:48:05 CEST 2013


On 10/17/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> That makes avformat & avcodec thread safe without the need to explicitly
> register a lock manager.
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavcodec/utils.c |   26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index 3832b81..cf7be5e 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -56,9 +56,33 @@
>  # include <iconv.h>
>  #endif
>
> +static int default_lockmgr_cb(void **mutex, enum AVLockOp op)
> +{
> +    void * volatile *state = mutex;
> +
> +    switch (op) {
> +    case AV_LOCK_CREATE:
> +        *state = NULL;
> +        return 0;
> +    case AV_LOCK_OBTAIN:
> +        while (avpriv_atomic_ptr_cas(state, NULL, mutex))
> +            ;
> +
> +        return 0;
> +    case AV_LOCK_RELEASE:
> +         if (avpriv_atomic_ptr_cas(state, mutex, NULL) != mutex)
> +             av_assert0(0);
> +
> +        return 0;
> +    case AV_LOCK_DESTROY:
> +        return 0;
> +    }
> +    return 1;
> +}
> +
>  volatile int ff_avcodec_locked;
>  static int volatile entangled_thread_counter = 0;
> -static int (*lockmgr_cb)(void **mutex, enum AVLockOp op);
> +static int (*lockmgr_cb)(void **mutex, enum AVLockOp op) =
> default_lockmgr_cb;
>  static void *codec_mutex;
>  static void *avformat_mutex;
>
> --
> 1.7.9.5
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>

Why this was not done before?


More information about the ffmpeg-devel mailing list