diff mbox

[FFmpeg-devel,5/7] avfilter/avfilter: convert to stdatomic

Message ID 20170322233412.6952-6-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer March 22, 2017, 11:34 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavfilter/avfilter.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

wm4 March 23, 2017, 6:16 a.m. UTC | #1
On Wed, 22 Mar 2017 20:34:10 -0300
James Almer <jamrial@gmail.com> wrote:

> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavfilter/avfilter.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index b431990edc..049c5ff47c 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.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/avassert.h"
>  #include "libavutil/avstring.h"
>  #include "libavutil/buffer.h"
> @@ -580,13 +581,14 @@ AVFilter *avfilter_get_by_name(const char *name)
>  int avfilter_register(AVFilter *filter)
>  {
>      AVFilter **f = last_filter;
> +    const AVFilter *cmp = NULL;
>  
>      /* the filter must select generic or internal exclusively */
>      av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE);
>  
>      filter->next = NULL;
>  
> -    while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
> +    while(*f || !atomic_compare_exchange_strong(f, &cmp, filter))
>          f = &(*f)->next;
>      last_filter = &filter->next;
>  

Patches 2-5 are OK, but work only with real atomics. (All this
"lock free" code is another case of having to deal with barely justified
messes that were committed before, instead of having implemented a
cleaner solution, but whatever.)
diff mbox

Patch

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index b431990edc..049c5ff47c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.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/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/buffer.h"
@@ -580,13 +581,14 @@  AVFilter *avfilter_get_by_name(const char *name)
 int avfilter_register(AVFilter *filter)
 {
     AVFilter **f = last_filter;
+    const AVFilter *cmp = NULL;
 
     /* the filter must select generic or internal exclusively */
     av_assert0((filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE) != AVFILTER_FLAG_SUPPORT_TIMELINE);
 
     filter->next = NULL;
 
-    while(*f || avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
+    while(*f || !atomic_compare_exchange_strong(f, &cmp, filter))
         f = &(*f)->next;
     last_filter = &filter->next;