• Wan-Teh Chang's avatar
    avutil: fix data race in av_get_cpu_flags() · 2170017a
    Wan-Teh Chang authored
    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: 's avatarWan-Teh Chang <wtc@google.com>
    2170017a
Name
Last commit
Last update
..
.gitignore Loading commit data...
adler32.c Loading commit data...
aes.c Loading commit data...
avstring.c Loading commit data...
base64.c Loading commit data...
blowfish.c Loading commit data...
cpu.c Loading commit data...
cpu_init.c Loading commit data...
crc.c Loading commit data...
des.c Loading commit data...
eval.c Loading commit data...
fifo.c Loading commit data...
float_dsp.c Loading commit data...
hmac.c Loading commit data...
lfg.c Loading commit data...
lls.c Loading commit data...
md5.c Loading commit data...
opt.c Loading commit data...
parseutils.c Loading commit data...
sha.c Loading commit data...
tree.c Loading commit data...
xtea.c Loading commit data...