diff options
| author | Laytan <laytanlaats@hotmail.com> | 2024-10-28 19:20:43 +0100 |
|---|---|---|
| committer | Laytan <laytanlaats@hotmail.com> | 2024-10-28 19:20:43 +0100 |
| commit | afed3ce6b5ae00d12e46f2799f16e286369ef3b3 (patch) | |
| tree | 783c48d98d0729081e8ed529d621ca2175f21388 /core/thread | |
| parent | e064f8c6bec2e656446b52afb35af7bfee02e6a9 (diff) | |
remove pthread from sys/unix and use sys/posix where used
Diffstat (limited to 'core/thread')
| -rw-r--r-- | core/thread/thread_unix.odin | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index 9576a3040..1e663bc87 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -4,14 +4,14 @@ package thread import "base:runtime" import "core:sync" -import "core:sys/unix" +import "core:sys/posix" _IS_SUPPORTED :: true // NOTE(tetra): Aligned here because of core/unix/pthread_linux.odin/pthread_t. // Also see core/sys/darwin/mach_darwin.odin/semaphore_t. Thread_Os_Specific :: struct #align(16) { - unix_thread: unix.pthread_t, // NOTE: very large on Darwin, small on Linux. + unix_thread: posix.pthread_t, // NOTE: very large on Darwin, small on Linux. start_ok: sync.Sema, } // @@ -23,7 +23,7 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { t := (^Thread)(t) // We need to give the thread a moment to start up before we enable cancellation. - can_set_thread_cancel_state := unix.pthread_setcancelstate(unix.PTHREAD_CANCEL_ENABLE, nil) == 0 + can_set_thread_cancel_state := posix.pthread_setcancelstate(.ENABLE, nil) == nil t.id = sync.current_thread_id() @@ -37,8 +37,8 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { // Enable thread's cancelability. if can_set_thread_cancel_state { - unix.pthread_setcanceltype (unix.PTHREAD_CANCEL_ASYNCHRONOUS, nil) - unix.pthread_setcancelstate(unix.PTHREAD_CANCEL_ENABLE, nil) + posix.pthread_setcanceltype (.ASYNCHRONOUS, nil) + posix.pthread_setcancelstate(.ENABLE, nil) } { @@ -59,8 +59,8 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { sync.atomic_or(&t.flags, { .Done }) if .Self_Cleanup in sync.atomic_load(&t.flags) { - res := unix.pthread_detach(t.unix_thread) - assert_contextless(res == 0) + res := posix.pthread_detach(t.unix_thread) + assert_contextless(res == nil) t.unix_thread = {} // NOTE(ftphikari): It doesn't matter which context 'free' received, right? @@ -71,19 +71,19 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { return nil } - attrs: unix.pthread_attr_t - if unix.pthread_attr_init(&attrs) != 0 { + attrs: posix.pthread_attr_t + if posix.pthread_attr_init(&attrs) != nil { return nil // NOTE(tetra, 2019-11-01): POSIX OOM. } - defer unix.pthread_attr_destroy(&attrs) + defer posix.pthread_attr_destroy(&attrs) // NOTE(tetra, 2019-11-01): These only fail if their argument is invalid. - res: i32 - res = unix.pthread_attr_setdetachstate(&attrs, unix.PTHREAD_CREATE_JOINABLE) - assert(res == 0) + res: posix.Errno + res = posix.pthread_attr_setdetachstate(&attrs, .CREATE_JOINABLE) + assert(res == nil) when ODIN_OS != .Haiku && ODIN_OS != .NetBSD { - res = unix.pthread_attr_setinheritsched(&attrs, unix.PTHREAD_EXPLICIT_SCHED) - assert(res == 0) + res = posix.pthread_attr_setinheritsched(&attrs, .EXPLICIT_SCHED) + assert(res == nil) } thread := new(Thread) @@ -93,26 +93,26 @@ _create :: proc(procedure: Thread_Proc, priority: Thread_Priority) -> ^Thread { thread.creation_allocator = context.allocator // Set thread priority. - policy: i32 + policy: posix.Sched_Policy when ODIN_OS != .Haiku && ODIN_OS != .NetBSD { - res = unix.pthread_attr_getschedpolicy(&attrs, &policy) - assert(res == 0) + res = posix.pthread_attr_getschedpolicy(&attrs, &policy) + assert(res == nil) } - params: unix.sched_param - res = unix.pthread_attr_getschedparam(&attrs, ¶ms) - assert(res == 0) - low := unix.sched_get_priority_min(policy) - high := unix.sched_get_priority_max(policy) + params: posix.sched_param + res = posix.pthread_attr_getschedparam(&attrs, ¶ms) + assert(res == nil) + low := posix.sched_get_priority_min(policy) + high := posix.sched_get_priority_max(policy) switch priority { case .Normal: // Okay case .Low: params.sched_priority = low + 1 case .High: params.sched_priority = high } - res = unix.pthread_attr_setschedparam(&attrs, ¶ms) - assert(res == 0) + res = posix.pthread_attr_setschedparam(&attrs, ¶ms) + assert(res == nil) thread.procedure = procedure - if unix.pthread_create(&thread.unix_thread, &attrs, __unix_thread_entry_proc, thread) != 0 { + if posix.pthread_create(&thread.unix_thread, &attrs, __unix_thread_entry_proc, thread) != nil { free(thread, thread.creation_allocator) return nil } @@ -130,7 +130,7 @@ _is_done :: proc(t: ^Thread) -> bool { } _join :: proc(t: ^Thread) { - if unix.pthread_equal(unix.pthread_self(), t.unix_thread) { + if posix.pthread_equal(posix.pthread_self(), t.unix_thread) { return } @@ -144,7 +144,7 @@ _join :: proc(t: ^Thread) { if .Started not_in sync.atomic_load(&t.flags) { _start(t) } - unix.pthread_join(t.unix_thread, nil) + posix.pthread_join(t.unix_thread, nil) } _join_multiple :: proc(threads: ..^Thread) { @@ -170,9 +170,9 @@ _terminate :: proc(t: ^Thread, exit_code: int) { // // This is in contrast to behavior I have seen on Linux where the thread is // just terminated. - unix.pthread_cancel(t.unix_thread) + posix.pthread_cancel(t.unix_thread) } _yield :: proc() { - unix.sched_yield() + posix.sched_yield() } |