Procházet zdrojové kódy

Merge pull request #617 from Tetralux/dep-yield-processor

Rename `yield_processor` to `cpu_relax`
gingerBill před 5 roky
rodič
revize
b725ae5ae0
2 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. 5 4
      core/sync/sync.odin
  2. 2 1
      core/thread/thread_unix.odin

+ 5 - 4
core/sync/sync.odin

@@ -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 - 1
core/thread/thread_unix.odin

@@ -2,6 +2,7 @@
 package thread;
 
 import "core:runtime"
+import "core:intrinsics"
 import "core:sync"
 import "core:sys/unix"
 
@@ -125,7 +126,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();
 		}
 	}