mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Update futex_haiku.odin
This commit is contained in:
@@ -3,6 +3,7 @@ package sync
|
|||||||
|
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:c/libc"
|
import "core:c/libc"
|
||||||
|
import "core:runtime"
|
||||||
import "core:sys/haiku"
|
import "core:sys/haiku"
|
||||||
import "core:sys/unix"
|
import "core:sys/unix"
|
||||||
import "core:time"
|
import "core:time"
|
||||||
@@ -20,24 +21,34 @@ Wait_Queue :: struct {
|
|||||||
}
|
}
|
||||||
@(private="file")
|
@(private="file")
|
||||||
waitq_lock :: proc "contextless" (waitq: ^Wait_Queue) {
|
waitq_lock :: proc "contextless" (waitq: ^Wait_Queue) {
|
||||||
|
// FIXME: Get rid of context here.
|
||||||
|
context = runtime.default_context()
|
||||||
for libc.atomic_flag_test_and_set_explicit(&waitq.lock, .acquire) {
|
for libc.atomic_flag_test_and_set_explicit(&waitq.lock, .acquire) {
|
||||||
; // spin...
|
; // spin...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@(private="file")
|
@(private="file")
|
||||||
waitq_unlock :: proc "contextless" (waitq: ^Wait_Queue) {
|
waitq_unlock :: proc "contextless" (waitq: ^Wait_Queue) {
|
||||||
|
// FIXME: Get rid of context here.
|
||||||
|
context = runtime.default_context()
|
||||||
libc.atomic_flag_clear_explicit(&waitq.lock, .release)
|
libc.atomic_flag_clear_explicit(&waitq.lock, .release)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This approach may scale badly in the future,
|
// FIXME: This approach may scale badly in the future,
|
||||||
// possible solution - hash map (leads to deadlocks now).
|
// possible solution - hash map (leads to deadlocks now).
|
||||||
@(private="file")
|
@(private="file")
|
||||||
g_waitq := Wait_Queue{
|
g_waitq: Wait_Queue
|
||||||
list = {
|
|
||||||
prev = &g_waitq.list,
|
@(init, private="file")
|
||||||
next = &g_waitq.list,
|
g_waitq_init :: proc() {
|
||||||
},
|
g_waitq = {
|
||||||
|
list = {
|
||||||
|
prev = &g_waitq.list,
|
||||||
|
next = &g_waitq.list,
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private="file")
|
@(private="file")
|
||||||
get_waitq :: #force_inline proc "contextless" (f: ^Futex) -> ^Wait_Queue {
|
get_waitq :: #force_inline proc "contextless" (f: ^Futex) -> ^Wait_Queue {
|
||||||
_ = f
|
_ = f
|
||||||
@@ -65,7 +76,7 @@ _futex_wait :: proc "contextless" (f: ^Futex, expect: u32) -> bool {
|
|||||||
haiku.sigaddset(&mask, haiku.SIGCONT)
|
haiku.sigaddset(&mask, haiku.SIGCONT)
|
||||||
unix.pthread_sigmask(haiku.SIG_BLOCK, &mask, &old_mask)
|
unix.pthread_sigmask(haiku.SIG_BLOCK, &mask, &old_mask)
|
||||||
|
|
||||||
if u32(atomic_load_explicit(f, .acquire)) == expect {
|
if u32(atomic_load_explicit(f, .Acquire)) == expect {
|
||||||
waitq_unlock(waitq)
|
waitq_unlock(waitq)
|
||||||
defer waitq_lock(waitq)
|
defer waitq_lock(waitq)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user