mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-01 19:02:13 +00:00
Remove context.thread_id
This commit is contained in:
@@ -329,8 +329,6 @@ Context :: struct {
|
||||
assertion_failure_proc: Assertion_Failure_Proc,
|
||||
logger: Logger,
|
||||
|
||||
thread_id: int,
|
||||
|
||||
user_data: any,
|
||||
user_ptr: rawptr,
|
||||
user_index: int,
|
||||
@@ -479,7 +477,6 @@ __init_context :: proc "contextless" (c: ^Context) {
|
||||
c.temp_allocator.procedure = default_temp_allocator_proc;
|
||||
c.temp_allocator.data = &global_default_temp_allocator_data;
|
||||
|
||||
c.thread_id = current_thread_id(); // NOTE(bill): This is "contextless" so it is okay to call
|
||||
c.assertion_failure_proc = default_assertion_failure_proc;
|
||||
|
||||
c.logger.procedure = default_logger_proc;
|
||||
|
||||
@@ -5,7 +5,3 @@ _OS_Errno :: distinct int;
|
||||
os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
return _os_write(data);
|
||||
}
|
||||
|
||||
current_thread_id :: proc "contextless" () -> int {
|
||||
return _current_thread_id();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,3 @@ _os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
n, err := os.write(os.stderr, data);
|
||||
return int(n), _OS_Errno(err);
|
||||
}
|
||||
|
||||
_current_thread_id :: proc "contextless" () -> int {
|
||||
return os.current_thread_id();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,3 @@ package runtime
|
||||
_os_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
|
||||
return 0, -1;
|
||||
}
|
||||
|
||||
_current_thread_id :: proc "contextless" () -> int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ foreign kernel32 {
|
||||
WriteFile :: proc(hFile: rawptr, lpBuffer: rawptr, nNumberOfBytesToWrite: u32, lpNumberOfBytesWritten: ^u32, lpOverlapped: rawptr) -> b32 ---
|
||||
GetLastError :: proc() -> u32 ---
|
||||
|
||||
// current_thread_id
|
||||
GetCurrentThreadId :: proc() -> u32 ---
|
||||
|
||||
// default_allocator
|
||||
GetProcessHeap :: proc() -> rawptr ---
|
||||
HeapAlloc :: proc(hHeap: rawptr, dwFlags: u32, dwBytes: uint) -> rawptr ---
|
||||
@@ -61,11 +58,6 @@ _os_write :: proc "contextless" (data: []byte) -> (n: int, err: _OS_Errno) {
|
||||
return;
|
||||
}
|
||||
|
||||
_current_thread_id :: proc "contextless" () -> int {
|
||||
return int(GetCurrentThreadId());
|
||||
}
|
||||
|
||||
|
||||
heap_alloc :: proc "contextless" (size: int) -> rawptr {
|
||||
HEAP_ZERO_MEMORY :: 0x00000008;
|
||||
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, uint(size));
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user