From d3f2f9480032f081cfafdb0223e6fb49a6834fd4 Mon Sep 17 00:00:00 2001 From: Tetralux Date: Tue, 21 Apr 2020 15:22:42 +0100 Subject: [PATCH 1/2] Remove outdated comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is what I get for removing the ability to provide a stack at the last minute.... 🤣 --- core/thread/thread_unix.odin | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index 53b8790d7..a11fe1c5d 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -40,15 +40,6 @@ Thread_Priority :: enum { // Creates a thread which will run the given procedure. // It then waits for `start` to be called. // -// You may provide a slice of bytes to use as the stack for the new thread, -// but if you do, you are expected to set up the guard pages yourself. -// -// The stack must also be aligned appropriately for the platform. -// We require it's at least 16 bytes aligned to help robustness; other -// platforms may require page-size alignment. -// Note also that pthreads requires the stack is at least 6 OS pages in size: -// 4 are required by pthreads, and two extra for guards pages that will be applied. -// create :: proc(procedure: Thread_Proc, priority := Thread_Priority.Normal) -> ^Thread { __linux_thread_entry_proc :: proc "c" (t: rawptr) -> rawptr { t := (^Thread)(t); From 8dd1b61aa248d08a14fe7b23dd5616bc6b9ab607 Mon Sep 17 00:00:00 2001 From: Tetralux Date: Tue, 21 Apr 2020 16:07:18 +0000 Subject: [PATCH 2/2] `sync.yield_processor` -> `sync.cpu_relax`; have it call `intrinsics.cpu_relax` --- core/sync/sync.odin | 9 +++++---- core/thread/thread_unix.odin | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/sync/sync.odin b/core/sync/sync.odin index 5a0512275..a899fdc8a 100644 --- a/core/sync/sync.odin +++ b/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(); } } diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index 53b8790d7..fe31ce1ff 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -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(); } }