avfilter/avfilter: Make avfilter_register() thread safe
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 28 Jun 2013 10:39:26 +0000 (12:39 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 28 Jun 2013 10:44:03 +0000 (12:44 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavfilter/avfilter.c

index 9e3977c..c3228cd 100644 (file)
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/atomic.h"
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/channel_layout.h"
@@ -465,11 +466,11 @@ int avfilter_register(AVFilter *filter)
                     || (!input->start_frame && !input->end_frame));
     }
 
-    while (*f)
-        f = &(*f)->next;
-    *f = filter;
     filter->next = NULL;
 
+    while(avpriv_atomic_ptr_cas((void * volatile *)f, NULL, filter))
+        f = &(*f)->next;
+
     return 0;
 }