From f327bcab927b60dac831d6cdbe263ff2b3a4ef6f Mon Sep 17 00:00:00 2001 From: Ignacy Koper Date: Tue, 28 Apr 2026 18:06:48 +0200 Subject: [PATCH] removed Haiku from core:sync, and core:thread Signed-off-by: Ignacy Koper --- core/sync/futex_haiku.odin | 164 -------------------------------- core/sync/primitives_haiku.odin | 8 -- core/thread/thread_unix.odin | 6 +- 3 files changed, 3 insertions(+), 175 deletions(-) delete mode 100644 core/sync/futex_haiku.odin delete mode 100644 core/sync/primitives_haiku.odin diff --git a/core/sync/futex_haiku.odin b/core/sync/futex_haiku.odin deleted file mode 100644 index 52321644a..000000000 --- a/core/sync/futex_haiku.odin +++ /dev/null @@ -1,164 +0,0 @@ -#+private -package sync - -import "core:sys/haiku" -import "core:sys/posix" -import "core:time" - -@(private="file") -Wait_Node :: struct { - thread: posix.pthread_t, - futex: ^Futex, - prev, next: ^Wait_Node, -} -@(private="file") -atomic_flag :: distinct bool -@(private="file") -Wait_Queue :: struct { - lock: atomic_flag, - list: Wait_Node, -} -@(private="file") -waitq_lock :: proc "contextless" (waitq: ^Wait_Queue) { - for cast(bool)atomic_exchange_explicit(&waitq.lock, atomic_flag(true), .Acquire) { - cpu_relax() // spin... - } -} -@(private="file") -waitq_unlock :: proc "contextless" (waitq: ^Wait_Queue) { - atomic_store_explicit(&waitq.lock, atomic_flag(false), .Release) -} - -// FIXME: This approach may scale badly in the future, -// possible solution - hash map (leads to deadlocks now). -@(private="file") -g_waitq: Wait_Queue - -@(init, private="file") -g_waitq_init :: proc() { - g_waitq = { - list = { - prev = &g_waitq.list, - next = &g_waitq.list, - }, - } -} - -@(private="file") -get_waitq :: #force_inline proc "contextless" (f: ^Futex) -> ^Wait_Queue { - _ = f - return &g_waitq -} - -_futex_wait :: proc "contextless" (f: ^Futex, expect: u32) -> (ok: bool) { - waitq := get_waitq(f) - waitq_lock(waitq) - defer waitq_unlock(waitq) - - head := &waitq.list - waiter := Wait_Node{ - thread = posix.pthread_self(), - futex = f, - prev = head, - next = head.next, - } - - waiter.prev.next = &waiter - waiter.next.prev = &waiter - - old_mask, mask: posix.sigset_t - posix.sigemptyset(&mask) - posix.sigaddset(&mask, .SIGCONT) - posix.pthread_sigmask(.BLOCK, &mask, &old_mask) - - if u32(atomic_load_explicit(f, .Acquire)) == expect { - waitq_unlock(waitq) - defer waitq_lock(waitq) - - sig: posix.Signal - errno := posix.sigwait(&mask, &sig) - ok = errno == nil - } - - waiter.prev.next = waiter.next - waiter.next.prev = waiter.prev - - _ = posix.pthread_sigmask(.SETMASK, &old_mask, nil) - - // FIXME: Add error handling! - return -} - -_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expect: u32, duration: time.Duration) -> (ok: bool) { - if duration <= 0 { - return false - } - waitq := get_waitq(f) - waitq_lock(waitq) - defer waitq_unlock(waitq) - - head := &waitq.list - waiter := Wait_Node{ - thread = posix.pthread_self(), - futex = f, - prev = head, - next = head.next, - } - - waiter.prev.next = &waiter - waiter.next.prev = &waiter - - old_mask, mask: posix.sigset_t - posix.sigemptyset(&mask) - posix.sigaddset(&mask, .SIGCONT) - posix.pthread_sigmask(.BLOCK, &mask, &old_mask) - - if u32(atomic_load_explicit(f, .Acquire)) == expect { - waitq_unlock(waitq) - defer waitq_lock(waitq) - - info: posix.siginfo_t - ts := posix.timespec{ - tv_sec = posix.time_t(i64(duration / 1e9)), - tv_nsec = i64(duration % 1e9), - } - haiku.sigtimedwait(&mask, &info, &ts) - errno := posix.errno() - ok = errno == .EAGAIN || errno == nil - } - - waiter.prev.next = waiter.next - waiter.next.prev = waiter.prev - - posix.pthread_sigmask(.SETMASK, &old_mask, nil) - - // FIXME: Add error handling! - return -} - -_futex_signal :: proc "contextless" (f: ^Futex) { - waitq := get_waitq(f) - waitq_lock(waitq) - defer waitq_unlock(waitq) - - head := &waitq.list - for waiter := head.next; waiter != head; waiter = waiter.next { - if waiter.futex == f { - posix.pthread_kill(waiter.thread, .SIGCONT) - break - } - } -} - -_futex_broadcast :: proc "contextless" (f: ^Futex) { - waitq := get_waitq(f) - waitq_lock(waitq) - defer waitq_unlock(waitq) - - head := &waitq.list - for waiter := head.next; waiter != head; waiter = waiter.next { - if waiter.futex == f { - posix.pthread_kill(waiter.thread, .SIGCONT) - } - } -} diff --git a/core/sync/primitives_haiku.odin b/core/sync/primitives_haiku.odin deleted file mode 100644 index 69d005206..000000000 --- a/core/sync/primitives_haiku.odin +++ /dev/null @@ -1,8 +0,0 @@ -#+private -package sync - -import "core:sys/haiku" - -_current_thread_id :: proc "contextless" () -> int { - return int(haiku.find_thread(nil)) -} diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index af2a4a3c1..02e628df5 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -1,4 +1,4 @@ -#+build linux, darwin, freebsd, openbsd, netbsd, haiku +#+build linux, darwin, freebsd, openbsd, netbsd #+private package thread @@ -83,7 +83,7 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { // NOTE(tetra, 2019-11-01): These only fail if their argument is invalid. res = posix.pthread_attr_setdetachstate(&attrs, .CREATE_JOINABLE) assert(res == nil) - when ODIN_OS != .Haiku && ODIN_OS != .NetBSD { + when ODIN_OS != .NetBSD { res = posix.pthread_attr_setinheritsched(&attrs, .EXPLICIT_SCHED) assert(res == nil) } @@ -96,7 +96,7 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { // Set thread priority. policy: posix.Sched_Policy - when ODIN_OS != .Haiku && ODIN_OS != .NetBSD { + when ODIN_OS != .NetBSD { res = posix.pthread_attr_getschedpolicy(&attrs, &policy) assert(res == nil) }