[FFmpeg-devel] [PATCH 3/4] avfilter/allfilters: make avfilter_register_all thread safe
Muhammad Faiz
mfcc64 at gmail.com
Mon Mar 6 21:47:38 EET 2017
Signed-off-by: Muhammad Faiz <mfcc64 at gmail.com>
---
libavfilter/allfilters.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 15a74c4..2042b35 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -19,6 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdatomic.h>
+
#include "avfilter.h"
#include "config.h"
#include "opencl_allkernels.h"
@@ -39,11 +41,14 @@
void avfilter_register_all(void)
{
- static int initialized;
+ static atomic_int initialized;
+ static atomic_int ready;
- if (initialized)
+ if (atomic_exchange_explicit(&initialized, 1, memory_order_relaxed)) {
+ while (!atomic_load_explicit(&ready, memory_order_relaxed))
+ ;
return;
- initialized = 1;
+ }
REGISTER_FILTER(ABENCH, abench, af);
REGISTER_FILTER(ACOMPRESSOR, acompressor, af);
@@ -379,4 +384,6 @@ void avfilter_register_all(void)
REGISTER_FILTER_UNCONDITIONAL(af_afifo);
REGISTER_FILTER_UNCONDITIONAL(vf_fifo);
ff_opencl_register_filter_kernel_code_all();
+
+ atomic_store_explicit(&ready, 1, memory_order_relaxed);
}
--
2.9.3
More information about the ffmpeg-devel
mailing list