summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2013-12-09 18:35:45 -0500
committerKeith Packard <keithp@keithp.com>2014-06-17 13:46:42 -0700
commitd3efccb33fa599d48004b22f2e07a19da4aaf789 (patch)
tree80e2a42e0daec5ea44a42fb08b5186b909de9173
parent2b3415a32d44b9b51bf57877bb61d982667c10f0 (diff)
Add support for FreeBSD using umtx (v3).
This fixes a sign-extension bug in the previous versions. Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org> Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--configure.ac11
-rw-r--r--src/xshmfence_futex.h24
2 files changed, 34 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index b855029..74b70e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,16 @@ AC_ARG_ENABLE(futex, AS_HELP_STRING([--enable-futex], [Enable futexes (default:
[FUTEX=$enableval], [FUTEX=auto])
if test "x$FUTEX" = "xauto"; then
- AC_CHECK_HEADER([linux/futex.h], [FUTEX=yes], [FUTEX=no])
+ AC_CHECK_HEADER([linux/futex.h], [FUTEX=yes])
+fi
+
+if test "x$FUTEX" = "xauto"; then
+ AC_CHECK_HEADER([sys/umtx.h], [FUTEX=yes], [FUTEX=no],
+ [#include <errno.h>
+ #include <sys/types.h>])
+ if test "x$FUTEX" = "xyes"; then
+ AC_DEFINE(HAVE_UMTX, 1, [Use umtx])
+ fi
fi
if test "x$FUTEX" = "xyes"; then
diff --git a/src/xshmfence_futex.h b/src/xshmfence_futex.h
index ed60b6d..ea96cf4 100644
--- a/src/xshmfence_futex.h
+++ b/src/xshmfence_futex.h
@@ -1,5 +1,6 @@
/*
* Copyright © 2013 Keith Packard
+ * Copyright © 2013 Jung-uk Kim <jkim@FreeBSD.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
@@ -24,6 +25,27 @@
#define _XSHMFENCE_FUTEX_H_
#include <errno.h>
+
+#ifdef HAVE_UMTX
+
+#include <sys/types.h>
+#include <sys/umtx.h>
+
+static inline int sys_futex(void *addr, int op, int32_t val)
+{
+ return _umtx_op(addr, op, (uint32_t)val, NULL, NULL) == -1 ? errno : 0;
+}
+
+static inline int futex_wake(int32_t *addr) {
+ return sys_futex(addr, UMTX_OP_WAKE, INT_MAX);
+}
+
+static inline int futex_wait(int32_t *addr, int32_t value) {
+ return sys_futex(addr, UMTX_OP_WAIT_UINT, value);
+}
+
+#else
+
#include <stdint.h>
#include <values.h>
#include <linux/futex.h>
@@ -43,6 +65,8 @@ static inline int futex_wait(int32_t *addr, int32_t value) {
return sys_futex(addr, FUTEX_WAIT, value, NULL, NULL, 0);
}
+#endif
+
#define barrier() __asm__ __volatile__("": : :"memory")
static inline void atomic_store(int32_t *f, int32_t v)