From aa5f58ce897e5eba7e655fb62e6caa002a42215a Mon Sep 17 00:00:00 2001 From: Jan Maria Matejka Date: Mon, 10 Sep 2018 15:11:55 +0200 Subject: [PATCH] Autoconf: check whether pthread spinlock is implemented This check is needed to build with pthreads on Android --- aclocal.m4 | 26 ++++++++++++++++++++++++-- configure.ac | 8 +++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/aclocal.m4 b/aclocal.m4 index c401d447..d70ca7cf 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -17,8 +17,6 @@ AC_DEFUN([BIRD_CHECK_PTHREADS], [ pthread_t pt; pthread_create(&pt, NULL, NULL, NULL); - pthread_spinlock_t lock; - pthread_spin_lock(&lock); ] ) ], @@ -31,6 +29,30 @@ AC_DEFUN([BIRD_CHECK_PTHREADS], CFLAGS="$bird_tmp_cflags" ]) +dnl ** Android API before version 24 doesn't implement spinlocks. +AC_DEFUN([BIRD_CHECK_PTHREAD_SPINLOCK], +[ + AC_CACHE_CHECK( + [whether POSIX threads provide spinlocks], + [bird_cv_lib_pthread_spinlock], + [ + AC_LINK_IFELSE( + [ + AC_LANG_PROGRAM( + [ #include ], + [ + pthread_spinlock_t lock; + pthread_spin_lock(&lock); + ] + ) + ], + [bird_cv_lib_pthread_spinlock=yes], + [bird_cv_lib_pthread_spinlock=no] + ) + ] + ) +]) + AC_DEFUN([BIRD_CHECK_MPLS_KERNEL], [ AC_CACHE_CHECK( diff --git a/configure.ac b/configure.ac index 943d3a7b..cfda4c7f 100644 --- a/configure.ac +++ b/configure.ac @@ -120,7 +120,13 @@ if test "$enable_pthreads" != no ; then AC_DEFINE([USE_PTHREADS], [1], [Define to 1 if pthreads are enabled]) CFLAGS="$CFLAGS -pthread" LDFLAGS="$LDFLAGS -pthread" - proto_bfd=bfd + + BIRD_CHECK_PTHREAD_SPINLOCK + if test "$bird_cv_lib_pthread_spinlock" = yes ; then + AC_DEFINE([USE_PTHREAD_SPINLOCK], [1], [Define to 1 if pthreads provide spinlocks]) + proto_bfd=bfd + fi + elif test "$enable_pthreads" = yes ; then AC_MSG_ERROR([POSIX threads not available.]) fi