[FFmpeg-devel] [PATCH 0/7] convert most of the remaining files to stdatomic

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


On Thu, 23 Mar 2017 00:28:15 -0300
James Almer <jamrial at gmail.com> wrote:

> From 3bf230d5f611ae5d1511e4629f742fc96b379b7f Mon Sep 17 00:00:00 2001
> From: James Almer <jamrial at gmail.com>
> Date: Wed, 22 Mar 2017 23:43:54 -0300
> Subject: [PATCH] avformat/format: convert to stdatomic
> 
> ---
>  libavformat/format.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/format.c b/libavformat/format.c
> index 38ca2a3465..781f341936 100644
> --- a/libavformat/format.c
> +++ b/libavformat/format.c
> @@ -19,7 +19,8 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> -#include "libavutil/atomic.h"
> +#include <stdatomic.h>
> +
>  #include "libavutil/avstring.h"
>  #include "libavutil/bprint.h"
>  #include "libavutil/opt.h"
> @@ -61,9 +62,10 @@ AVOutputFormat *av_oformat_next(const AVOutputFormat *f)
>  void av_register_input_format(AVInputFormat *format)
>  {
>      AVInputFormat **p = last_iformat;
> +    const AVInputFormat *cmp = NULL;
>  
>      // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
> -    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
> +    while(p != &format->next && !format->next && !atomic_compare_exchange_strong((atomic_intptr_t *)p, (intptr_t *)&cmp, (intptr_t)format))
>          p = &(*p)->next;
>  
>      if (!format->next)
> @@ -73,9 +75,10 @@ void av_register_input_format(AVInputFormat *format)
>  void av_register_output_format(AVOutputFormat *format)
>  {
>      AVOutputFormat **p = last_oformat;
> +    const AVOutputFormat *cmp = NULL;
>  
>      // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
> -    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
> +    while(p != &format->next && !format->next && !atomic_compare_exchange_strong((atomic_intptr_t *)p, (intptr_t *)&cmp, (intptr_t)format))
>          p = &(*p)->next;
>  
>      if (!format->next)

Looks like undefined behavior. Atomic variables must be, well, atomic.
You can't just cast them. Declare them as atomic in the first place.

For some silly reason, we don't have pointer atomics, only
atomic_intptr_t. So it'll be a bit of a pain.


More information about the ffmpeg-devel mailing list