From 2170017a1cd033b6f28e16476921022712a522d8 Mon Sep 17 00:00:00 2001 From: Wan-Teh Chang Date: Wed, 7 Dec 2016 16:16:02 -0800 Subject: avutil: fix data race in av_get_cpu_flags() Make the one-time initialization in av_get_cpu_flags() thread-safe. The static variables |flags|, |cpuflags_mask|, and |checked| in libavutil/cpu.c are read and written using normal load and store operations. These are considered as data races. The fix is to use atomic load and store operations. Remove the |checked| variable because the invalid value of -1 for |flags| can be used to indicate the same condition. Rename |flags| to |cpu_flags| and move it to file scope. The fix can be verified by running the libavutil/tests/cpu_init.c test program under ThreadSanitizer: ./configure --toolchain=clang-tsan make libavutil/tests/cpu_init libavutil/tests/cpu_init There should be no warnings from ThreadSanitizer. Co-author: Dmitry Vyukov of Google, who suggested the data race fix. Signed-off-by: Wan-Teh Chang --- tests/fate/libavutil.mak | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak index 2824e084eb..8b17411370 100644 --- a/tests/fate/libavutil.mak +++ b/tests/fate/libavutil.mak @@ -25,6 +25,11 @@ fate-cpu: libavutil/tests/cpu$(EXESUF) fate-cpu: CMD = run libavutil/tests/cpu $(CPUFLAGS:%=-c%) $(THREADS:%=-t%) fate-cpu: REF = /dev/null +FATE_LIBAVUTIL-$(HAVE_THREADS) += fate-cpu_init +fate-cpu_init: libavutil/tests/cpu_init$(EXESUF) +fate-cpu_init: CMD = run libavutil/tests/cpu_init +fate-cpu_init: REF = /dev/null + FATE_LIBAVUTIL += fate-crc fate-crc: libavutil/tests/crc$(EXESUF) fate-crc: CMD = run libavutil/tests/crc @@ -73,5 +78,6 @@ FATE_LIBAVUTIL += fate-xtea fate-xtea: libavutil/tests/xtea$(EXESUF) fate-xtea: CMD = run libavutil/tests/xtea +FATE_LIBAVUTIL += $(FATE_LIBAVUTIL-yes) FATE-$(CONFIG_AVUTIL) += $(FATE_LIBAVUTIL) fate-libavutil: $(FATE_LIBAVUTIL) -- cgit v1.2.3