mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 20:02:22 -07:00
sync.yield_processor -> sync.cpu_relax; have it call intrinsics.cpu_relax
This commit is contained in:
+5
-4
@@ -1,8 +1,9 @@
|
||||
package sync
|
||||
|
||||
foreign {
|
||||
@(link_name="llvm.x86.sse2.pause")
|
||||
yield_processor :: proc() ---
|
||||
import "core:intrinsics"
|
||||
|
||||
cpu_relax :: inline proc() {
|
||||
intrinsics.cpu_relax();
|
||||
}
|
||||
|
||||
Ticket_Mutex :: struct {
|
||||
@@ -18,7 +19,7 @@ ticket_mutex_init :: proc(m: ^Ticket_Mutex) {
|
||||
ticket_mutex_lock :: inline proc(m: ^Ticket_Mutex) {
|
||||
ticket := atomic_add(&m.ticket, 1, .Relaxed);
|
||||
for ticket != m.serving {
|
||||
yield_processor();
|
||||
intrinsics.cpu_relax();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package thread;
|
||||
|
||||
import "core:runtime"
|
||||
import "core:intrinsics"
|
||||
import "core:sync"
|
||||
import "core:sys/unix"
|
||||
|
||||
@@ -134,7 +135,7 @@ join :: proc(t: ^Thread) {
|
||||
if sync.atomic_swap(&t.already_joined, true, .Sequentially_Consistent) {
|
||||
for {
|
||||
if sync.atomic_load(&t.done, .Sequentially_Consistent) do return;
|
||||
sync.yield_processor();
|
||||
intrinsics.cpu_relax();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user