aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Davidson <colrdavidson@gmail.com>2022-12-29 11:05:31 -0800
committerColin Davidson <colrdavidson@gmail.com>2022-12-29 11:05:31 -0800
commit04a4dbcdafe9a1e31c4bce215dfd5222c3e7275e (patch)
treec1fce4f60c5e5709c54e7a5788c02fb191b7293a
parentef9e31cb31ce6c87687b7932ecd0ace3a33b494f (diff)
add freebsd support
-rw-r--r--src/threading.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/threading.cpp b/src/threading.cpp
index 70a7072e7..1de277259 100644
--- a/src/threading.cpp
+++ b/src/threading.cpp
@@ -473,6 +473,37 @@ gb_internal void tpool_wait_on_addr(Futex *addr, Footex val) {
}
}
}
+
+#if defined(GB_SYSTEM_FREEBSD)
+
+#include <sys/types.h>
+#include <sys/umtx.h>
+
+typedef std::atomic<int32_t> Futex;
+typedef volatile int32_t Footex;
+
+gb_internal void tpool_wake_addr(Futex *addr) {
+ _umtx_op(addr, UMTX_OP_WAKE, 1, 0, 0);
+}
+
+gb_internal void tpool_wait_on_addr(Futex *addr, Footex val) {
+ for (;;) {
+ int ret = _umtx_op(addr, UMTX_OP_WAIT_UINT, val, 0, NULL);
+ if (ret == 0) {
+ if (errno == ETIMEDOUT || errno == EINTR) {
+ continue;
+ }
+
+ perror("Futex wait");
+ GB_PANIC("Failed in futex wait!\n");
+ } else if (ret == 0) {
+ if (*addr != val) {
+ return;
+ }
+ }
+ }
+}
+
#elif defined(GB_SYSTEM_OSX)
typedef std::atomic<int64_t> Futex;