Support for sys_futex autodetection
authorMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Thu, 8 Oct 2009 19:18:56 +0000 (15:18 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Thu, 8 Oct 2009 19:18:56 +0000 (15:18 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Makefile.am
configure.ac
tests/Makefile.am
urcu-defer.c
urcu-qsbr-static.h
urcu-qsbr.c
urcu-static.h
urcu.c

index f7d64f67bdf10caf37910ff5be957872dbceb88b..28e414c3c186fffcec498c216ae17ecaaaae50d8 100644 (file)
@@ -6,8 +6,9 @@ AM_LDFLAGS=-lpthread
 SUBDIRS = tests
 
 include_HEADERS = urcu.h $(top_srcdir)/urcu-*.h
-nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h urcu/rculist.h urcu/system.h
-nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic_arch.h
+nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h \
+               urcu/rculist.h urcu/system.h urcu/urcu-futex.h
+nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic_arch.h urcu/config.h
 
 EXTRA_DIST = $(top_srcdir)/urcu/arch_*.h $(top_srcdir)/urcu/uatomic_arch_*.h \
                gpl-2.0.txt lgpl-2.1.txt lgpl-relicensing.txt \
@@ -19,6 +20,9 @@ else
 COMPAT=
 endif
 
+if COMPAT_FUTEX
+COMPAT+=compat_futex.c
+endif
 
 lib_LTLIBRARIES = liburcu.la liburcu-mb.la liburcu-defer.la liburcu-qsbr.la liburcu-bp.la
 
index 40603c41f6452171de1b159f9e736eafdcba9d2d..2c1b6c00b26ce5c2bebe19c0e2eca4098459cd5f 100644 (file)
@@ -12,6 +12,7 @@ AC_CONFIG_SRCDIR([urcu.h])
 AH_TEMPLATE([CONFIG_SMP], [Enable SMP support. With SMP support enabled, uniprocessors are also supported. With SMP support disabled, UP systems work fine, but the behavior of SMP systems is undefined.])
 AH_TEMPLATE([CONFIG_HAVE_FENCE], [Defined when on a system that has memory fence
 instructions.])
+AH_TEMPLATE([CONFIG_HAVE_FUTEX], [Defined when on a system with futex support.])
 AC_CONFIG_HEADERS([config.h])
 
 # Checks for programs.
@@ -59,9 +60,33 @@ if test "x$ARCHTYPE" = "xx86" -a "x$target_cpu" != "xi386" -a "x$target_cpu" !=
 fi
 ]
 
+AC_MSG_CHECKING([presence of sys_futex()])
+AC_TRY_COMPILE(
+[
+#include <sys/syscall.h>
+],
+[
+#ifndef __NR_futex
+#error "futexes not available"
+#endif
+],
+[
+       AC_MSG_RESULT([yes])
+       AC_DEFINE([CONFIG_HAVE_FUTEX], [1])
+       compat_futex_test=0
+]
+,
+[
+       AC_MSG_RESULT([no])
+       compat_futex_test=1
+]
+)
+
+AM_CONDITIONAL([COMPAT_FUTEX], [ test "x$compat_futex_test" = "x1" ])
+
 AM_CONDITIONAL([GCC_API], [test "x$ARCHTYPE" != xx86 -a "x$ARCHTYPE" != xppc])
 
-AM_CONDITIONAL([COMPAT_ARCH], [test "x$SUBARCHTYPE" == xx86compat ])
+AM_CONDITIONAL([COMPAT_ARCH], [test "x$SUBARCHTYPE" = xx86compat ])
 
 AC_ARG_ENABLE([smp-support], [  --disable-smp-support   Disable SMP support. Warning: only use this
                           on uniprocessor systems. [[default=enabled]]], [def_smp_support=$enableval], [def_smp_support="yes"])
index 983ee6777890819ced85bc519aae9b30f8e91266..fdc82b11303e7a506dde08c0049550d01b20c349 100644 (file)
@@ -14,11 +14,15 @@ noinst_PROGRAMS = test_urcu test_urcu_dynamic_link test_urcu_timing \
 noinst_HEADERS = rcutorture.h
 
 if COMPAT_ARCH
-COMPAT=$(top_builddir)/compat_arch_@ARCHTYPE@.c
+COMPAT=$(top_srcdir)/compat_arch_@ARCHTYPE@.c
 else
 COMPAT=
 endif
 
+if COMPAT_FUTEX
+COMPAT+=$(top_srcdir)/compat_futex.c
+endif
+
 URCU_SIGNAL=$(top_builddir)/urcu.c $(top_builddir)/urcu-pointer.c $(COMPAT)
 # URCU_SIGNAL_YIELD uses urcu.c but -DDEBUG_YIELD must be defined
 URCU_SIGNAL_YIELD=$(top_builddir)/urcu.c $(top_builddir)/urcu-pointer.c $(COMPAT)
index a38b5c0b9418af76287b3e552fd089f278cb5e55..ed627a356a0b58e938e89eaea83f7f58333aee52 100644 (file)
 #include <syscall.h>
 #include <unistd.h>
 
+#include "urcu/urcu-futex.h"
 #include "urcu-defer-static.h"
 /* Do not #define _LGPL_SOURCE to ensure we can emit the wrapper symbols */
 #include "urcu-defer.h"
 
-#define futex(...)     syscall(__NR_futex, __VA_ARGS__)
-#define FUTEX_WAIT             0
-#define FUTEX_WAKE             1
-
 void __attribute__((destructor)) urcu_defer_exit(void);
 
 extern void synchronize_rcu(void);
@@ -101,7 +98,7 @@ static void wake_up_defer(void)
 {
        if (unlikely(uatomic_read(&defer_thread_futex) == -1)) {
                uatomic_set(&defer_thread_futex, 0);
-               futex(&defer_thread_futex, FUTEX_WAKE, 1,
+               futex_noasync(&defer_thread_futex, FUTEX_WAKE, 1,
                      NULL, NULL, 0);
        }
 }
@@ -134,7 +131,7 @@ static void wait_defer(void)
        } else {
                smp_rmb();      /* Read queue before read futex */
                if (uatomic_read(&defer_thread_futex) == -1)
-                       futex(&defer_thread_futex, FUTEX_WAIT, -1,
+                       futex_noasync(&defer_thread_futex, FUTEX_WAIT, -1,
                              NULL, NULL, 0);
        }
 }
index 150bc09bbc8c1779598bf6fdf435284120225aed..e49a04186104bbc2b3b769665a1fb6cb59fe7911 100644 (file)
 #include <urcu/system.h>
 #include <urcu/uatomic_arch.h>
 #include <urcu/list.h>
-
-#define futex(...)             syscall(__NR_futex, __VA_ARGS__)
-#define FUTEX_WAIT             0
-#define FUTEX_WAKE             1
+#include <urcu/urcu-futex.h>
 
 /*
  * This code section can only be included in LGPL 2.1 compatible source code.
@@ -154,7 +151,7 @@ static inline void wake_up_gp(void)
 {
        if (unlikely(uatomic_read(&gp_futex) == -1)) {
                uatomic_set(&gp_futex, 0);
-               futex(&gp_futex, FUTEX_WAKE, 1,
+               futex_noasync(&gp_futex, FUTEX_WAKE, 1,
                      NULL, NULL, 0);
        }
 }
index 56d86f9e561d6ea8fc372eed83ffc36f35dc358b..5c6d49bb8fc5faa8f7364c9ce32ee53aed53a0a6 100644 (file)
@@ -102,7 +102,7 @@ static void wait_gp(void)
        /* Read reader_gp before read futex */
        smp_rmb();
        if (uatomic_read(&gp_futex) == -1)
-               futex(&gp_futex, FUTEX_WAIT, -1,
+               futex_noasync(&gp_futex, FUTEX_WAIT, -1,
                      NULL, NULL, 0);
 }
 
index 2e7371ef5000194c2d302803c7ba4a359a64c7d3..97d94dc0b8817b5a87e83fafb3de9d3c6bd011b1 100644 (file)
 #include <urcu/system.h>
 #include <urcu/uatomic_arch.h>
 #include <urcu/list.h>
-
-#define futex(...)             syscall(__NR_futex, __VA_ARGS__)
-#define FUTEX_WAIT             0
-#define FUTEX_WAKE             1
+#include <urcu/urcu-futex.h>
 
 /*
  * This code section can only be included in LGPL 2.1 compatible source code.
@@ -182,7 +179,7 @@ static inline void wake_up_gp(void)
 {
        if (unlikely(uatomic_read(&gp_futex) == -1)) {
                uatomic_set(&gp_futex, 0);
-               futex(&gp_futex, FUTEX_WAKE, 1,
+               futex_async(&gp_futex, FUTEX_WAKE, 1,
                      NULL, NULL, 0);
        }
 }
diff --git a/urcu.c b/urcu.c
index 8ff39db1331e5a33cfc102b9fb3283e6c58fc2df..0ebe4fd796927a7cd2d204cfff75ed746e55dc91 100644 (file)
--- a/urcu.c
+++ b/urcu.c
@@ -208,7 +208,7 @@ static void wait_gp(void)
        /* Read reader_gp before read futex */
        force_mb_all_threads();
        if (uatomic_read(&gp_futex) == -1)
-               futex(&gp_futex, FUTEX_WAIT, -1,
+               futex_async(&gp_futex, FUTEX_WAIT, -1,
                      NULL, NULL, 0);
 }
 
This page took 0.028959 seconds and 4 git commands to generate.