]> git.sesse.net Git - ffmpeg/commit
avutil: fix data race in av_get_cpu_flags()
authorWan-Teh Chang <wtc-at-google.com@ffmpeg.org>
Wed, 7 Dec 2016 02:16:13 +0000 (18:16 -0800)
committerMichael Niedermayer <michael@niedermayer.cc>
Mon, 12 Dec 2016 23:07:20 +0000 (00:07 +0100)
commitfed50c4304eecb352e29ce789cdb96ea84d6162f
tree2514d8429a6926deb5a056b7417a747c0431c7d1
parent4cf3def805cf522ddd9c24c24ef1246b008bac2c
avutil: fix data race in av_get_cpu_flags()

Make the one-time initialization in av_get_cpu_flags() thread-safe. The
static variable |cpu_flags| in libavutil/cpu.c is 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.

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>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavutil/cpu.c
libavutil/cpu.h