removed Haiku from core:sync, and core:thread

Signed-off-by: Ignacy Koper <ignacy423@gmail.com>
This commit is contained in:
Ignacy Koper
2026-04-28 18:06:48 +02:00
parent b5cb4b96fc
commit f327bcab92
3 changed files with 3 additions and 175 deletions

View File

@@ -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)
}
}
}

View File

@@ -1,8 +0,0 @@
#+private
package sync
import "core:sys/haiku"
_current_thread_id :: proc "contextless" () -> int {
return int(haiku.find_thread(nil))
}

View File

@@ -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)
}