From 8e7cf4bc992f13dbb523bb42d6b9de4bc2f486c2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 21 May 2014 01:04:47 +0200 Subject: atomics: switch to C11 stdatomic.h In my opinion, we shouldn't use atomics at all, but ok. This switches the mpv code to use C11 stdatomic.h, and for compilers that don't support stdatomic.h yet, we emulate the subset used by mpv using the builtins commonly provided by gcc and clang. This supersedes an earlier similar attempt by Kovensky. That attempt unfortunately relied on a big copypasted freebsd header (which also depended on much more highly compiler-specific functionality, defined reserved symbols, etc.), so it had to be NIH'ed. Some issues: - C11 says default initialization of atomics "produces a valid state", but it's not sure whether the stored value is really 0. But we rely on this. - I'm pretty sure our use of the __atomic... builtins is/was incorrect. We don't use atomic load/store intrinsics, and access stuff directly. - Our wrapper actually does stricter typechecking than the stdatomic.h implementation by gcc 4.9. We make the atomic types incompatible with normal types by wrapping them into structs. (The FreeBSD wrapper does the same.) - I couldn't test on MinGW. --- old-configure | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'old-configure') diff --git a/old-configure b/old-configure index 819676ed6b..03ee0a5eb8 100755 --- a/old-configure +++ b/old-configure @@ -268,7 +268,7 @@ exit 0 # If autodetection is available then the third state is: auto _pkg_config=auto _cc=auto -test "$CC" && _cc="$CC" +test -n "$CC" && _cc="$CC" _opt=-O2 _prefix="/usr/local" options_state_machine init @@ -485,19 +485,25 @@ extra_cflags="$extra_cflags -D_REENTRANT -D_THREAD_SAFE" compile_check waftools/fragments/pthreads.c "$_ld_pthread" || die "Unable to find pthreads support." echores "yes" -check_statement_libs "compiler support for __atomic built-ins" auto ATOMIC_BUILTINS \ +check_statement_libs "support for stdatomic.h" auto STDATOMIC \ + stdatomic.h '_Atomic int test = ATOMIC_VAR_INIT(123); int test2 = atomic_load(&test)' +_stdatomic=$(defretval) + +_atomic=auto +test "$_stdatomic" = yes && _atomic=no +check_statement_libs "compiler support for __atomic built-ins" $_atomic ATOMIC_BUILTINS \ stdint.h 'int64_t test = 0; test = __atomic_add_fetch(&test, 1, __ATOMIC_SEQ_CST)' \ " " "-latomic" _atomic=$(defretval) _sync=auto -test "$_atomic" = yes && _sync=no +(test "$_atomic" = yes || test "$_stdatomic" = yes ) && _sync=no check_statement_libs "compiler support for __sync built-ins" $_sync SYNC_BUILTINS \ stdint.h 'int64_t test = 0; test = __sync_add_and_fetch(&test, 1)' _sync=$(defretval) -if test "$_atomic" = no && test "$_sync" = no ; then - die "your compiler must support either __atomic or __sync built-ins." +if test "$_atomic" = no && test "$_sync" = no && test "$_stdatomic" = no ; then + die "your compiler must support either stdatomic.h, or __atomic, or __sync built-ins." fi check_compile "iconv" $_iconv ICONV waftools/fragments/iconv.c " " "-liconv" "-liconv $_ld_dl" -- cgit v1.2.3