mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Use contextless procs in core:sync instead
This commit is contained in:
@@ -48,12 +48,12 @@ wait_group_add :: proc "contextless" (wg: ^Wait_Group, delta: int) {
|
|||||||
|
|
||||||
atomic_add(&wg.counter, delta)
|
atomic_add(&wg.counter, delta)
|
||||||
if wg.counter < 0 {
|
if wg.counter < 0 {
|
||||||
_panic("sync.Wait_Group negative counter")
|
panic_contextless("sync.Wait_Group negative counter")
|
||||||
}
|
}
|
||||||
if wg.counter == 0 {
|
if wg.counter == 0 {
|
||||||
cond_broadcast(&wg.cond)
|
cond_broadcast(&wg.cond)
|
||||||
if wg.counter != 0 {
|
if wg.counter != 0 {
|
||||||
_panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
panic_contextless("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ wait_group_wait :: proc "contextless" (wg: ^Wait_Group) {
|
|||||||
if wg.counter != 0 {
|
if wg.counter != 0 {
|
||||||
cond_wait(&wg.cond, &wg.mutex)
|
cond_wait(&wg.cond, &wg.mutex)
|
||||||
if wg.counter != 0 {
|
if wg.counter != 0 {
|
||||||
_panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
panic_contextless("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ wait_group_wait_with_timeout :: proc "contextless" (wg: ^Wait_Group, duration: t
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if wg.counter != 0 {
|
if wg.counter != 0 {
|
||||||
_panic("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
panic_contextless("sync.Wait_Group misuse: sync.wait_group_add called concurrently with sync.wait_group_wait")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -494,7 +494,7 @@ for other threads for entering.
|
|||||||
*/
|
*/
|
||||||
recursive_benaphore_unlock :: proc "contextless" (b: ^Recursive_Benaphore) {
|
recursive_benaphore_unlock :: proc "contextless" (b: ^Recursive_Benaphore) {
|
||||||
tid := current_thread_id()
|
tid := current_thread_id()
|
||||||
_assert(tid == b.owner, "tid != b.owner")
|
assert_contextless(tid == b.owner, "tid != b.owner")
|
||||||
b.recursion -= 1
|
b.recursion -= 1
|
||||||
recursion := b.recursion
|
recursion := b.recursion
|
||||||
if recursion == 0 {
|
if recursion == 0 {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati
|
|||||||
case -ETIMEDOUT:
|
case -ETIMEDOUT:
|
||||||
return false
|
return false
|
||||||
case:
|
case:
|
||||||
_panic("darwin.os_sync_wait_on_address_with_timeout failure")
|
panic_contextless("darwin.os_sync_wait_on_address_with_timeout failure")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati
|
|||||||
case ETIMEDOUT:
|
case ETIMEDOUT:
|
||||||
return false
|
return false
|
||||||
case:
|
case:
|
||||||
_panic("futex_wait failure")
|
panic_contextless("futex_wait failure")
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ _futex_signal :: proc "contextless" (f: ^Futex) {
|
|||||||
case -ENOENT:
|
case -ENOENT:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("darwin.os_sync_wake_by_address_any failure")
|
panic_contextless("darwin.os_sync_wake_by_address_any failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -99,7 +99,7 @@ _futex_signal :: proc "contextless" (f: ^Futex) {
|
|||||||
case ENOENT:
|
case ENOENT:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("futex_wake_single failure")
|
panic_contextless("futex_wake_single failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ _futex_broadcast :: proc "contextless" (f: ^Futex) {
|
|||||||
case -ENOENT:
|
case -ENOENT:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("darwin.os_sync_wake_by_address_all failure")
|
panic_contextless("darwin.os_sync_wake_by_address_all failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -135,7 +135,7 @@ _futex_broadcast :: proc "contextless" (f: ^Futex) {
|
|||||||
case ENOENT:
|
case ENOENT:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("futex_wake_all failure")
|
panic_contextless("futex_wake_all failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ _futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_panic("_futex_wait failure")
|
panic_contextless("_futex_wait failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
unreachable()
|
unreachable()
|
||||||
@@ -44,14 +44,14 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_panic("_futex_wait_with_timeout failure")
|
panic_contextless("_futex_wait_with_timeout failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_signal :: proc "contextless" (f: ^Futex) {
|
_futex_signal :: proc "contextless" (f: ^Futex) {
|
||||||
errno := freebsd._umtx_op(f, .WAKE, 1, nil, nil)
|
errno := freebsd._umtx_op(f, .WAKE, 1, nil, nil)
|
||||||
|
|
||||||
if errno != nil {
|
if errno != nil {
|
||||||
_panic("_futex_signal failure")
|
panic_contextless("_futex_signal failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +59,6 @@ _futex_broadcast :: proc "contextless" (f: ^Futex) {
|
|||||||
errno := freebsd._umtx_op(f, .WAKE, cast(c.ulong)max(i32), nil, nil)
|
errno := freebsd._umtx_op(f, .WAKE, cast(c.ulong)max(i32), nil, nil)
|
||||||
|
|
||||||
if errno != nil {
|
if errno != nil {
|
||||||
_panic("_futex_broadcast failure")
|
panic_contextless("_futex_broadcast failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ _futex_wait :: proc "contextless" (futex: ^Futex, expected: u32) -> bool {
|
|||||||
return true
|
return true
|
||||||
case:
|
case:
|
||||||
// TODO(flysand): More descriptive panic messages based on the vlaue of `errno`
|
// TODO(flysand): More descriptive panic messages based on the vlaue of `errno`
|
||||||
_panic("futex_wait failure")
|
panic_contextless("futex_wait failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ _futex_wait_with_timeout :: proc "contextless" (futex: ^Futex, expected: u32, du
|
|||||||
case .NONE, .EINTR, .EAGAIN:
|
case .NONE, .EINTR, .EAGAIN:
|
||||||
return true
|
return true
|
||||||
case:
|
case:
|
||||||
_panic("futex_wait_with_timeout failure")
|
panic_contextless("futex_wait_with_timeout failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ _futex_signal :: proc "contextless" (futex: ^Futex) {
|
|||||||
case .NONE:
|
case .NONE:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("futex_wake_single failure")
|
panic_contextless("futex_wake_single failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,6 +57,6 @@ _futex_broadcast :: proc "contextless" (futex: ^Futex) {
|
|||||||
case .NONE:
|
case .NONE:
|
||||||
return
|
return
|
||||||
case:
|
case:
|
||||||
_panic("_futex_wake_all failure")
|
panic_contextless("_futex_wake_all failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ _futex_wait :: proc "contextless" (futex: ^Futex, expected: u32) -> bool {
|
|||||||
case EINTR, EAGAIN:
|
case EINTR, EAGAIN:
|
||||||
return true
|
return true
|
||||||
case:
|
case:
|
||||||
_panic("futex_wait failure")
|
panic_contextless("futex_wait failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -55,7 +55,7 @@ _futex_wait_with_timeout :: proc "contextless" (futex: ^Futex, expected: u32, du
|
|||||||
case ETIMEDOUT:
|
case ETIMEDOUT:
|
||||||
return false
|
return false
|
||||||
case:
|
case:
|
||||||
_panic("futex_wait_with_timeout failure")
|
panic_contextless("futex_wait_with_timeout failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -63,12 +63,12 @@ _futex_wait_with_timeout :: proc "contextless" (futex: ^Futex, expected: u32, du
|
|||||||
|
|
||||||
_futex_signal :: proc "contextless" (futex: ^Futex) {
|
_futex_signal :: proc "contextless" (futex: ^Futex) {
|
||||||
if _, ok := intrinsics.syscall_bsd(unix.SYS___futex, uintptr(futex), FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); !ok {
|
if _, ok := intrinsics.syscall_bsd(unix.SYS___futex, uintptr(futex), FUTEX_WAKE_PRIVATE, 1, 0, 0, 0); !ok {
|
||||||
_panic("futex_wake_single failure")
|
panic_contextless("futex_wake_single failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_broadcast :: proc "contextless" (futex: ^Futex) {
|
_futex_broadcast :: proc "contextless" (futex: ^Futex) {
|
||||||
if _, ok := intrinsics.syscall_bsd(unix.SYS___futex, uintptr(futex), FUTEX_WAKE_PRIVATE, uintptr(max(i32)), 0, 0, 0); !ok {
|
if _, ok := intrinsics.syscall_bsd(unix.SYS___futex, uintptr(futex), FUTEX_WAKE_PRIVATE, uintptr(max(i32)), 0, 0, 0); !ok {
|
||||||
_panic("_futex_wake_all failure")
|
panic_contextless("_futex_wake_all failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ _futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_panic("futex_wait failure")
|
panic_contextless("futex_wait failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, duration: time.Duration) -> bool {
|
_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, duration: time.Duration) -> bool {
|
||||||
@@ -62,14 +62,14 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_panic("futex_wait_with_timeout failure")
|
panic_contextless("futex_wait_with_timeout failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
_futex_signal :: proc "contextless" (f: ^Futex) {
|
_futex_signal :: proc "contextless" (f: ^Futex) {
|
||||||
res := _unix_futex(f, FUTEX_WAKE_PRIVATE, 1, nil)
|
res := _unix_futex(f, FUTEX_WAKE_PRIVATE, 1, nil)
|
||||||
|
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
_panic("futex_wake_single failure")
|
panic_contextless("futex_wake_single failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +77,6 @@ _futex_broadcast :: proc "contextless" (f: ^Futex) {
|
|||||||
res := _unix_futex(f, FUTEX_WAKE_PRIVATE, u32(max(i32)), nil)
|
res := _unix_futex(f, FUTEX_WAKE_PRIVATE, u32(max(i32)), nil)
|
||||||
|
|
||||||
if res == -1 {
|
if res == -1 {
|
||||||
_panic("_futex_wake_all failure")
|
panic_contextless("_futex_wake_all failure")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import "core:time"
|
|||||||
|
|
||||||
_futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool {
|
_futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool {
|
||||||
when !intrinsics.has_target_feature("atomics") {
|
when !intrinsics.has_target_feature("atomics") {
|
||||||
_panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
panic_contextless("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
||||||
} else {
|
} else {
|
||||||
s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, -1)
|
s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, -1)
|
||||||
return s != 0
|
return s != 0
|
||||||
@@ -19,7 +19,7 @@ _futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool {
|
|||||||
|
|
||||||
_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, duration: time.Duration) -> bool {
|
_futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, duration: time.Duration) -> bool {
|
||||||
when !intrinsics.has_target_feature("atomics") {
|
when !intrinsics.has_target_feature("atomics") {
|
||||||
_panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
panic_contextless("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
||||||
} else {
|
} else {
|
||||||
s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, i64(duration))
|
s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, i64(duration))
|
||||||
return s != 0
|
return s != 0
|
||||||
@@ -28,7 +28,7 @@ _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, durati
|
|||||||
|
|
||||||
_futex_signal :: proc "contextless" (f: ^Futex) {
|
_futex_signal :: proc "contextless" (f: ^Futex) {
|
||||||
when !intrinsics.has_target_feature("atomics") {
|
when !intrinsics.has_target_feature("atomics") {
|
||||||
_panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
panic_contextless("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
||||||
} else {
|
} else {
|
||||||
loop: for {
|
loop: for {
|
||||||
s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), 1)
|
s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), 1)
|
||||||
@@ -41,7 +41,7 @@ _futex_signal :: proc "contextless" (f: ^Futex) {
|
|||||||
|
|
||||||
_futex_broadcast :: proc "contextless" (f: ^Futex) {
|
_futex_broadcast :: proc "contextless" (f: ^Futex) {
|
||||||
when !intrinsics.has_target_feature("atomics") {
|
when !intrinsics.has_target_feature("atomics") {
|
||||||
_panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
panic_contextless("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it")
|
||||||
} else {
|
} else {
|
||||||
loop: for {
|
loop: for {
|
||||||
s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), ~u32(0))
|
s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), ~u32(0))
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package sync
|
package sync
|
||||||
|
|
||||||
import "base:runtime"
|
|
||||||
import "core:time"
|
import "core:time"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -560,7 +559,7 @@ futex_wait :: proc "contextless" (f: ^Futex, expected: u32) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ok := _futex_wait(f, expected)
|
ok := _futex_wait(f, expected)
|
||||||
_assert(ok, "futex_wait failure")
|
assert_contextless(ok, "futex_wait failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -597,18 +596,3 @@ Wake up multiple threads waiting on a futex.
|
|||||||
futex_broadcast :: proc "contextless" (f: ^Futex) {
|
futex_broadcast :: proc "contextless" (f: ^Futex) {
|
||||||
_futex_broadcast(f)
|
_futex_broadcast(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@(private)
|
|
||||||
_assert :: proc "contextless" (cond: bool, msg: string) {
|
|
||||||
if !cond {
|
|
||||||
_panic(msg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@(private)
|
|
||||||
_panic :: proc "contextless" (msg: string) -> ! {
|
|
||||||
runtime.print_string(msg)
|
|
||||||
runtime.print_byte('\n')
|
|
||||||
runtime.trap()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ atomic_recursive_mutex_lock :: proc "contextless" (m: ^Atomic_Recursive_Mutex) {
|
|||||||
|
|
||||||
atomic_recursive_mutex_unlock :: proc "contextless" (m: ^Atomic_Recursive_Mutex) {
|
atomic_recursive_mutex_unlock :: proc "contextless" (m: ^Atomic_Recursive_Mutex) {
|
||||||
tid := current_thread_id()
|
tid := current_thread_id()
|
||||||
_assert(tid == m.owner, "tid != m.owner")
|
assert_contextless(tid == m.owner, "tid != m.owner")
|
||||||
m.recursion -= 1
|
m.recursion -= 1
|
||||||
recursion := m.recursion
|
recursion := m.recursion
|
||||||
if recursion == 0 {
|
if recursion == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user