diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2015-05-29 09:56:51 +0200 | 
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2017-03-31 17:59:45 +0200 | 
| commit | 899a4fd2a14bf51b8a37e6d0fadd5dbf9395b427 (patch) | |
| tree | 4749d7a3ac4e9e10fd213e76863fc6c117d228ac /configure.ac | |
| parent | 8aa42b826c2037ddc68a32712caf2dfbda9981f8 (diff) | |
build: try to find some kind of atomic ops
Either one of:
- ISO C11
- gcc __atomic_*
- gcc/clang __sync_*
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'configure.ac')
| -rwxr-xr-x | configure.ac | 66 | 
1 files changed, 66 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index b8cebd8d23..4875a6849d 100755 --- a/configure.ac +++ b/configure.ac @@ -541,6 +541,72 @@ AC_CHECK_HEADERS([stropts.h sys/ksym.h \  	linux/version.h asm/types.h \  	sys/cdefs.h]) +ac_stdatomic_ok=false +AC_DEFINE(FRR_AUTOCONF_ATOMIC, 1, [did autoconf checks for atomic funcs]) +AC_CHECK_HEADER([stdatomic.h],[ + +  AC_MSG_CHECKING([whether _Atomic qualifier works]) +  AC_LINK_IFELSE([AC_LANG_SOURCE([[ +#include <stdatomic.h> +int main(int argc, char **argv) { +  _Atomic int i = 0; +  return i; +} +]])], [ +    AC_DEFINE(HAVE_STDATOMIC_H, 1, [found stdatomic.h]) +    AC_MSG_RESULT([yes]) +    ac_stdatomic_ok=true +  ], [ +    AC_MSG_RESULT([no]) +  ]) +]) + +AS_IF([$ac_stdatomic_ok], [true], [ +  AC_MSG_CHECKING([for __atomic_* builtins]) +  AC_LINK_IFELSE([AC_LANG_SOURCE([[ +int main(int argc, char **argv) { +  volatile int i = 1; +  __atomic_store_n (&i, 0, __ATOMIC_RELEASE); +  return __atomic_load_n (&i, __ATOMIC_ACQUIRE); +} +]])], [ +    AC_DEFINE(HAVE___ATOMIC, 1, [found __atomic builtins]) +    AC_MSG_RESULT([yes]) +  ], [ +    AC_MSG_RESULT([no]) + +    dnl FreeBSD 9 has a broken stdatomic.h where _Atomic doesn't work +    AC_MSG_CHECKING([for __sync_* builtins]) +    AC_LINK_IFELSE([AC_LANG_SOURCE([[ +int main(int argc, char **argv) { +  volatile int i = 1; +  __sync_fetch_and_sub (&i, 1); +  return __sync_val_compare_and_swap (&i, 0, 1); +} +]])], [ +      AC_DEFINE(HAVE___SYNC, 1, [found __sync builtins]) +      AC_MSG_RESULT([yes]) + +      AC_MSG_CHECKING([for __sync_swap builtin]) +      AC_LINK_IFELSE([AC_LANG_SOURCE([[ +int main(int argc, char **argv) { +  volatile int i = 1; +  return __sync_swap (&i, 2); +} +]])], [ +        AC_DEFINE(HAVE___SYNC_SWAP, 1, [found __sync_swap builtin]) +        AC_MSG_RESULT([yes]) +      ], [ +        AC_MSG_RESULT([no]) +      ]) + +    ], [ +      AC_MSG_RESULT([no]) +      AC_MSG_FAILURE([stdatomic.h unavailable and $CC has neither __atomic nor __sync builtins]) +    ]) +  ]) +]) +  dnl Utility macro to avoid retyping includes all the time  m4_define([FRR_INCLUDES],  [#ifdef SUNOS_5  | 
