]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Autoconf: check whether pthread spinlock is implemented
authorJan Maria Matejka <mq@ucw.cz>
Mon, 10 Sep 2018 13:11:55 +0000 (15:11 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Thu, 13 Sep 2018 09:12:04 +0000 (11:12 +0200)
This check is needed to build with pthreads on Android

aclocal.m4
configure.ac

index c401d447b9c95eb3180834eba657c065a4f818bb..d70ca7cf682ac6fb13fd269a61bf93b216c68f2c 100644 (file)
@@ -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.h> ],
+           [
+             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(
index 943d3a7b31dc69ad061bd18df76a7458e945e519..cfda4c7f5f513b4f8e8afb8b6246d6a5d7e47385 100644 (file)
@@ -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