summaryrefslogtreecommitdiff
path: root/libavutil/cpu.h
diff options
context:
space:
mode:
authorWan-Teh Chang <wtc@google.com>2016-12-07 16:16:02 -0800
committerVittorio Giovara <vittorio.giovara@gmail.com>2016-12-08 15:53:58 -0500
commit2170017a1cd033b6f28e16476921022712a522d8 (patch)
treecfcbe102ef4c0fcddd52e2b51b9fca5a850db146 /libavutil/cpu.h
parentd5759701a82926059ae3e2530805e900041a5419 (diff)
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 <wtc@google.com>
Diffstat (limited to 'libavutil/cpu.h')
-rw-r--r--libavutil/cpu.h2
1 files changed, 0 insertions, 2 deletions
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index deff4ccf55..c205ee16f6 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -73,8 +73,6 @@ int av_get_cpu_flags(void);
/**
* Set a mask on flags returned by av_get_cpu_flags().
* This function is mainly useful for testing.
- *
- * @warning this function is not thread safe.
*/
void av_set_cpu_flags_mask(int mask);