diff --git a/core/thread/thread.odin b/core/thread/thread.odin index 859b6597a..e5b4908e7 100644 --- a/core/thread/thread.odin +++ b/core/thread/thread.odin @@ -170,8 +170,9 @@ yield :: proc() { Get thread's name/description. This procedure returns the name of the given thread. If `thread` is `nil`, this procedure returns the name of the calling thread. +OS level errors are silently ignored. -**Note(linux, bsd)**: Because the thread name is stored in as the `cmdline`, if the thread name was not set, the command that has been used to create the process as the name of the thread. +**Note(linux, bsd)**: Because the thread name is stored in as the `cmdline`, if the thread name was not set, the command that has been used to create the process will be used as the name of the thread. allocates memory for the returned string using provided allocator. */ diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index dc1d13020..13b6fa264 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -206,17 +206,15 @@ _get_name :: proc(thread: ^Thread, allocator: runtime.Allocator, loc: runtime.So tid = thread.unix_thread } - buf := make([]u8, _MAX_PTHREAD_NAME_LENGTH, allocator, loc) or_return + buf : [_MAX_PTHREAD_NAME_LENGTH]u8 when ODIN_OS == .Darwin || ODIN_OS == .Linux || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD { - pthread_getname_np(tid, raw_data(buf), len(buf)) + pthread_getname_np(tid, raw_data(buf[:]), len(buf)) } else when ODIN_OS == .OpenBSD { - pthread_get_name_np(tid, raw_data(buf), len(buf)) + pthread_get_name_np(tid, raw_data(buf[:]), len(buf)) } - name = transmute(string)buf - name = strings.truncate_to_byte(name, 0) - + name, err = strings.clone_from_cstring(cstring(raw_data(buf[:])), allocator, loc) return } diff --git a/core/thread/thread_windows.odin b/core/thread/thread_windows.odin index 4695a5b84..0b5824f64 100644 --- a/core/thread/thread_windows.odin +++ b/core/thread/thread_windows.odin @@ -166,15 +166,14 @@ _get_name :: proc(thread: ^Thread, allocator: runtime.Allocator, loc: runtime.So t_handle = thread.win32_thread } - buf_16: win32.PWSTR + buf: win32.PWSTR - hr := win32.GetThreadDescription(t_handle, buf_16) - defer if win32.SUCCEEDED(hr) { - win32.LocalFree(rawptr(buf_16)) + hr := win32.GetThreadDescription(t_handle, &buf) + + if win32.SUCCEEDED(hr) { + defer win32.LocalFree(rawptr(buf)) + name, err = win32.wstring_to_utf8(buf, -1, allocator) } - - name = win32.wstring_to_utf8(buf_16, -1, allocator) or_return - return }