[FFmpeg-devel] [PATCH] avutil: fix data race in av_get_cpu_flags().
Michael Niedermayer
michael at niedermayer.cc
Tue Nov 22 02:35:12 EET 2016
On Mon, Nov 21, 2016 at 03:37:49PM -0800, Wan-Teh Chang wrote:
> Make the one-time initialization in av_get_cpu_flags() thread-safe.
> The fix assumes -1 is an invalid value for cpu flags.
please explain the bug / race that occurs and how it is fixed
>
> The fix requires new atomic functions to get, set, and compare-and-swap
> an integer without a memory barrier.
why ?
>
> The data race fix is written by Dmitry Vyukov of Google.
Then the author for the git patch should be set accordingly
[...]
> @@ -44,7 +45,20 @@
> #include <unistd.h>
> #endif
>
> -static int flags, checked;
> +static int cpu_flags = -1;
> +
> +static int get_cpu_flags(void)
> +{
> + if (ARCH_AARCH64)
> + return ff_get_cpu_flags_aarch64();
> + if (ARCH_ARM)
> + return ff_get_cpu_flags_arm();
> + if (ARCH_PPC)
> + return ff_get_cpu_flags_ppc();
> + if (ARCH_X86)
> + return ff_get_cpu_flags_x86();
> + /* Not reached. */
src/libavutil/cpu.c: In function ‘get_cpu_flags’:
src/libavutil/cpu.c:61: error: control reaches end of non-void function
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I have often repented speaking, but never of holding my tongue.
-- Xenocrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161122/4fbb5ea9/attachment.sig>
More information about the ffmpeg-devel
mailing list