[FFmpeg-devel] [PATCH 6/7] avutil/opencl: convert to stdatomic

wm4 nfxjfg at googlemail.com
Thu Mar 23 08:11:56 EET 2017


On Wed, 22 Mar 2017 20:34:11 -0300
James Almer <jamrial at gmail.com> wrote:

> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  libavutil/opencl.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/opencl.c b/libavutil/opencl.c
> index af35770e06..9b6c8d10d8 100644
> --- a/libavutil/opencl.c
> +++ b/libavutil/opencl.c
> @@ -29,7 +29,7 @@
>  
>  #if HAVE_THREADS
>  #include "thread.h"
> -#include "atomic.h"
> +#include <stdatomic.h>
>  
>  static pthread_mutex_t * volatile atomic_opencl_lock = NULL;
>  #define LOCK_OPENCL pthread_mutex_lock(atomic_opencl_lock)
> @@ -351,13 +351,14 @@ static inline int init_opencl_mtx(void)
>      if (!atomic_opencl_lock) {
>          int err;
>          pthread_mutex_t *tmp = av_malloc(sizeof(pthread_mutex_t));
> +        const pthread_mutex_t *cmp = NULL;
>          if (!tmp)
>              return AVERROR(ENOMEM);
>          if ((err = pthread_mutex_init(tmp, NULL))) {
>              av_free(tmp);
>              return AVERROR(err);
>          }
> -        if (avpriv_atomic_ptr_cas((void * volatile *)&atomic_opencl_lock, NULL, tmp)) {
> +        if (!atomic_compare_exchange_strong(&atomic_opencl_lock, &cmp, tmp)) {
>              pthread_mutex_destroy(tmp);
>              av_free(tmp);
>          }

Uh I guess that's ok (we really should add static mutex initializer
emulation on Windows).


More information about the ffmpeg-devel mailing list