diff options
| author | Andreas T Jonsson <mail@andreasjonsson.se> | 2024-05-10 09:04:52 +0200 |
|---|---|---|
| committer | Andreas T Jonsson <mail@andreasjonsson.se> | 2024-05-10 09:04:52 +0200 |
| commit | b72c2edabbc9087b07a30b781de1925d6570dd62 (patch) | |
| tree | 0e96f43038901ec8c6f6b015071c1803a2166d41 /core/sync | |
| parent | 273e4c6b4ce6f1060870782c8e780fe2b371ede4 (diff) | |
| parent | 41bd8cf7143902db59c02c56fc5318a7e749d7a5 (diff) | |
Merge branch 'master' into netbsd
Diffstat (limited to 'core/sync')
| -rw-r--r-- | core/sync/extended.odin | 2 | ||||
| -rw-r--r-- | core/sync/futex_wasm.odin | 44 |
2 files changed, 32 insertions, 14 deletions
diff --git a/core/sync/extended.odin b/core/sync/extended.odin index 76b7686fe..781ed816e 100644 --- a/core/sync/extended.odin +++ b/core/sync/extended.odin @@ -433,7 +433,7 @@ One_Shot_Event :: struct #no_copy { // Blocks the current thread until the event is made available with `one_shot_event_signal`. one_shot_event_wait :: proc "contextless" (e: ^One_Shot_Event) { for atomic_load_explicit(&e.state, .Acquire) == 0 { - futex_wait(&e.state, 1) + futex_wait(&e.state, 0) } } diff --git a/core/sync/futex_wasm.odin b/core/sync/futex_wasm.odin index de1013364..de88e8198 100644 --- a/core/sync/futex_wasm.odin +++ b/core/sync/futex_wasm.odin @@ -5,31 +5,49 @@ package sync import "base:intrinsics" import "core:time" +// NOTE: because `core:sync` is in the dependency chain of a lot of the core packages (mostly through `core:mem`) +// without actually calling into it much, I opted for a runtime panic instead of a compile error here. + _futex_wait :: proc "contextless" (f: ^Futex, expected: u32) -> bool { - s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, -1) - return s != 0 + when !intrinsics.has_target_feature("atomics") { + _panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it") + } else { + s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, -1) + return s != 0 + } } _futex_wait_with_timeout :: proc "contextless" (f: ^Futex, expected: u32, duration: time.Duration) -> bool { - s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, i64(duration)) - return s != 0 - + when !intrinsics.has_target_feature("atomics") { + _panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it") + } else { + s := intrinsics.wasm_memory_atomic_wait32((^u32)(f), expected, i64(duration)) + return s != 0 + } } _futex_signal :: proc "contextless" (f: ^Futex) { - loop: for { - s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), 1) - if s >= 1 { - return + when !intrinsics.has_target_feature("atomics") { + _panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it") + } else { + loop: for { + s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), 1) + if s >= 1 { + return + } } } } _futex_broadcast :: proc "contextless" (f: ^Futex) { - loop: for { - s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), ~u32(0)) - if s >= 0 { - return + when !intrinsics.has_target_feature("atomics") { + _panic("usage of `core:sync` requires the `-target-feature:\"atomics\"` or a `-microarch` that supports it") + } else { + loop: for { + s := intrinsics.wasm_memory_atomic_notify32((^u32)(f), ~u32(0)) + if s >= 0 { + return + } } } } |