From d42e876164c63eead9d0db6f53cda866f508cd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Bostr=C3=B6m?= Date: Fri, 25 Aug 2017 15:48:11 -0700 Subject: Add atomics to vp8 synchronization primitives. Fixes issue on iPad Pro 10.5 (and probably other places) where threads are not properly synchronized. On x86 this data race was benign as load and store instructions are atomic, they were being atomic in practice as the program hasn't been observed to be miscompiled. Such guarantees are not made outside x86, and real problems manifested where libvpx reliably reproduced a broken bitstream for even just the initial keyframe. This was detected in WebRTC where this device started using multithreading (as its CPU count is higher than earlier devices, where the problem did not manifest as single-threading was used in practice). This issue was not detected under thread-sanitizer bots as mutexes were conditionally used under this platform to simulate the protected read and write semantics that were in practice provided on x86 platforms. This change also removes several mutexes, so encoder/decoder state is lighter-weight after this change and we do not need to initialize so many mutexes (this was done even on non-thread-sanitizer platforms where they were unused). Change-Id: If41fcb0d99944f7bbc8ec40877cdc34d672ae72a --- vp8/encoder/bitstream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vp8/encoder/bitstream.c') diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c index 7086faae9..d7a17b749 100644 --- a/vp8/encoder/bitstream.c +++ b/vp8/encoder/bitstream.c @@ -1416,7 +1416,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, vp8_start_encode(&cpi->bc[1], cx_data, cx_data_end); #if CONFIG_MULTITHREAD - if (cpi->b_multi_threaded) { + if (vpx_atomic_load_acquire(&cpi->b_multi_threaded)) { pack_mb_row_tokens(cpi, &cpi->bc[1]); } else { vp8_pack_tokens(&cpi->bc[1], cpi->tok, cpi->tok_count); -- cgit v1.2.3