aboutsummaryrefslogtreecommitdiff
path: root/core/sync
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-06-08 15:57:00 +0100
committergingerBill <bill@gingerbill.org>2021-06-08 15:57:00 +0100
commit8ec2ca9dcd138f6f5e49cd3f6c6bb575a7e434e7 (patch)
treea30e214bceb68e34bcb6191a3abd4d1c54762fd3 /core/sync
parentf19bb0f4d45ba4352c4392807ca2b1efe5918ea7 (diff)
Remove `context.thread_id`
Diffstat (limited to 'core/sync')
-rw-r--r--core/sync/sync.odin6
-rw-r--r--core/sync/sync2/extended.odin6
-rw-r--r--core/sync/sync2/primitives.odin4
-rw-r--r--core/sync/sync2/primitives_atomic.odin6
-rw-r--r--core/sync/sync2/primitives_windows.odin4
-rw-r--r--core/sync/sync_darwin.odin13
-rw-r--r--core/sync/sync_freebsd.odin12
-rw-r--r--core/sync/sync_linux.odin12
-rw-r--r--core/sync/sync_windows.odin4
9 files changed, 58 insertions, 9 deletions
diff --git a/core/sync/sync.odin b/core/sync/sync.odin
index 06ec043bc..60d226d20 100644
--- a/core/sync/sync.odin
+++ b/core/sync/sync.odin
@@ -80,7 +80,7 @@ recursive_benaphore_destroy :: proc(b: ^Recursive_Benaphore) {
}
recursive_benaphore_lock :: proc(b: ^Recursive_Benaphore) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if intrinsics.atomic_add_acq(&b.counter, 1) > 1 {
if tid != b.owner {
semaphore_wait_for(&b.sema);
@@ -92,7 +92,7 @@ recursive_benaphore_lock :: proc(b: ^Recursive_Benaphore) {
}
recursive_benaphore_try_lock :: proc(b: ^Recursive_Benaphore) -> bool {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if b.owner == tid {
intrinsics.atomic_add_acq(&b.counter, 1);
} else {
@@ -108,7 +108,7 @@ recursive_benaphore_try_lock :: proc(b: ^Recursive_Benaphore) -> bool {
}
recursive_benaphore_unlock :: proc(b: ^Recursive_Benaphore) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
assert(tid == b.owner);
b.recursion -= 1;
recursion := b.recursion;
diff --git a/core/sync/sync2/extended.odin b/core/sync/sync2/extended.odin
index 06051c822..9ee796057 100644
--- a/core/sync/sync2/extended.odin
+++ b/core/sync/sync2/extended.odin
@@ -201,7 +201,7 @@ Recursive_Benaphore :: struct {
}
recursive_benaphore_lock :: proc(b: ^Recursive_Benaphore) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if atomic_add_acquire(&b.counter, 1) > 1 {
if tid != b.owner {
sema_wait(&b.sema);
@@ -213,7 +213,7 @@ recursive_benaphore_lock :: proc(b: ^Recursive_Benaphore) {
}
recursive_benaphore_try_lock :: proc(b: ^Recursive_Benaphore) -> bool {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if b.owner == tid {
atomic_add_acquire(&b.counter, 1);
}
@@ -228,7 +228,7 @@ recursive_benaphore_try_lock :: proc(b: ^Recursive_Benaphore) -> bool {
}
recursive_benaphore_unlock :: proc(b: ^Recursive_Benaphore) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
assert(tid == b.owner);
b.recursion -= 1;
recursion := b.recursion;
diff --git a/core/sync/sync2/primitives.odin b/core/sync/sync2/primitives.odin
index e524586ec..d0a4439d2 100644
--- a/core/sync/sync2/primitives.odin
+++ b/core/sync/sync2/primitives.odin
@@ -2,6 +2,10 @@ package sync2
import "core:time"
+current_thread_id :: proc "contextless" () -> int {
+ return _current_thread_id();
+}
+
// A Mutex is a mutual exclusion lock
// The zero value for a Mutex is an unlocked mutex
//
diff --git a/core/sync/sync2/primitives_atomic.odin b/core/sync/sync2/primitives_atomic.odin
index aed01eb1f..cfd06130d 100644
--- a/core/sync/sync2/primitives_atomic.odin
+++ b/core/sync/sync2/primitives_atomic.odin
@@ -233,7 +233,7 @@ Atomic_Recursive_Mutex :: struct {
}
atomic_recursive_mutex_lock :: proc(m: ^Atomic_Recursive_Mutex) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if tid != m.owner {
mutex_lock(&m.mutex);
}
@@ -243,7 +243,7 @@ atomic_recursive_mutex_lock :: proc(m: ^Atomic_Recursive_Mutex) {
}
atomic_recursive_mutex_unlock :: proc(m: ^Atomic_Recursive_Mutex) {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
assert(tid == m.owner);
m.recursion -= 1;
recursion := m.recursion;
@@ -258,7 +258,7 @@ atomic_recursive_mutex_unlock :: proc(m: ^Atomic_Recursive_Mutex) {
}
atomic_recursive_mutex_try_lock :: proc(m: ^Atomic_Recursive_Mutex) -> bool {
- tid := runtime.current_thread_id();
+ tid := current_thread_id();
if m.owner == tid {
return mutex_try_lock(&m.mutex);
}
diff --git a/core/sync/sync2/primitives_windows.odin b/core/sync/sync2/primitives_windows.odin
index 219af0162..582572aa9 100644
--- a/core/sync/sync2/primitives_windows.odin
+++ b/core/sync/sync2/primitives_windows.odin
@@ -5,6 +5,10 @@ package sync2
import "core:time"
import win32 "core:sys/windows"
+_current_thread_id :: proc "contextless" () -> int {
+ return int(win32.GetCurrentThreadId());
+}
+
_Mutex :: struct {
srwlock: win32.SRWLOCK,
}
diff --git a/core/sync/sync_darwin.odin b/core/sync/sync_darwin.odin
index 8153b4b37..c8e9632be 100644
--- a/core/sync/sync_darwin.odin
+++ b/core/sync/sync_darwin.odin
@@ -4,6 +4,19 @@ import "core:sys/darwin"
import "core:c"
+foreign import pthread "System.framework"
+
+current_thread_id :: proc "contextless" () -> int {
+ tid: u64;
+ // NOTE(Oskar): available from OSX 10.6 and iOS 3.2.
+ // For older versions there is `syscall(SYS_thread_selfid)`, but not really
+ // the same thing apparently.
+ foreign pthread { pthread_threadid_np :: proc "c" (rawptr, ^u64) -> c.int ---; }
+ pthread_threadid_np(nil, &tid);
+ return int(tid);
+}
+
+
// The Darwin docs say it best:
// A semaphore is much like a lock, except that a finite number of threads can hold it simultaneously.
// Semaphores can be thought of as being much like piles of tokens; multiple threads can take these tokens,
diff --git a/core/sync/sync_freebsd.odin b/core/sync/sync_freebsd.odin
index 7d1816cfe..87532621d 100644
--- a/core/sync/sync_freebsd.odin
+++ b/core/sync/sync_freebsd.odin
@@ -2,6 +2,18 @@ package sync
import "core:sys/unix"
+foreign import libc "system:c"
+
+current_thread_id :: proc "contextless" () -> int {
+ foreign libc {
+ syscall :: proc(number: i32, #c_vararg args: ..any) -> i32 ---
+ }
+
+ SYS_GETTID :: 186;
+ return int(syscall(SYS_GETTID));
+}
+
+
// The Darwin docs say it best:
// A semaphore is much like a lock, except that a finite number of threads can hold it simultaneously.
// Semaphores can be thought of as being much like piles of tokens; multiple threads can take these tokens,
diff --git a/core/sync/sync_linux.odin b/core/sync/sync_linux.odin
index 74f2b1e87..aa3c7a068 100644
--- a/core/sync/sync_linux.odin
+++ b/core/sync/sync_linux.odin
@@ -2,6 +2,18 @@ package sync
import "core:sys/unix"
+foreign import libc "system:c"
+
+current_thread_id :: proc "contextless" () -> int {
+ foreign libc {
+ syscall :: proc(number: i32, #c_vararg args: ..any) -> i32 ---
+ }
+
+ SYS_GETTID :: 186;
+ return int(syscall(SYS_GETTID));
+}
+
+
// The Darwin docs say it best:
// A semaphore is much like a lock, except that a finite number of threads can hold it simultaneously.
// Semaphores can be thought of as being much like piles of tokens; multiple threads can take these tokens,
diff --git a/core/sync/sync_windows.odin b/core/sync/sync_windows.odin
index 095f4a3d3..2bfd82567 100644
--- a/core/sync/sync_windows.odin
+++ b/core/sync/sync_windows.odin
@@ -4,6 +4,10 @@ package sync
import win32 "core:sys/windows"
import "core:time"
+current_thread_id :: proc "contextless" () -> int {
+ return int(win32.GetCurrentThreadId());
+}
+
// When waited upon, blocks until the internal count is greater than zero, then subtracts one.
// Posting to the semaphore increases the count by one, or the provided amount.