[Mesa-dev] [PATCH v2 2/5] util: emulate futex on FreeBSD using umtx
Greg V
greg at unrelenting.technology
Thu Jan 18 22:54:43 UTC 2018
Obtained from: FreeBSD ports
---
src/util/futex.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/util/futex.h b/src/util/futex.h
index 4402893069..425e34a2cd 100644
--- a/src/util/futex.h
+++ b/src/util/futex.h
@@ -51,6 +51,28 @@ static inline int futex_wait(uint32_t *addr, int32_t value, const struct timespe
FUTEX_BITSET_MATCH_ANY);
}
+#elif defined(__FreeBSD__)
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/umtx.h>
+
+static inline int sys_futex(void *addr1, int op, int val1, const struct timespec *timeout, void *addr2, int _)
+{
+ return _umtx_op(addr1, op, (uint32_t)val1, addr2, (void*)timeout) == -1 ? errno : 0;
+}
+
+static inline int futex_wake(uint32_t *addr, int count)
+{
+ return sys_futex(addr, UMTX_OP_WAKE, count, NULL, NULL, 0);
+}
+
+static inline int futex_wait(uint32_t *addr, int32_t value, int32_t _)
+{
+ return sys_futex(addr, UMTX_OP_WAIT_UINT, value, NULL, NULL, 0);
+}
+
#endif
#endif /* UTIL_FUTEX_H */
--
2.15.1
More information about the mesa-dev
mailing list