diff --git a/core/thread/thread.odin b/core/thread/thread.odin index 6a5f78156..56853a080 100644 --- a/core/thread/thread.odin +++ b/core/thread/thread.odin @@ -162,7 +162,7 @@ If thread is nil the procedure will get the name of the calling thread. allocates memory for the returned string using provided allocator. */ -get_name :: proc(thread: ^Thread, allocator := context.allocator, loc := #caller_location) -> (string, runtime.Allocator_Error) { +get_name :: proc(thread: ^Thread, allocator := context.temp_allocator, loc := #caller_location) -> (string, runtime.Allocator_Error) { return _get_name(thread, allocator, loc) } diff --git a/core/thread/thread_windows.odin b/core/thread/thread_windows.odin index 9281635e5..ba1da9aa8 100644 --- a/core/thread/thread_windows.odin +++ b/core/thread/thread_windows.odin @@ -163,15 +163,9 @@ _get_name :: proc(thread: ^Thread, allocator: runtime.Allocator, loc: runtime.So t_handle = thread.win32_thread } - buf_8: [_THREAD_DESCRIPTION_LENGTH * 2]u8 - buf_16: [_THREAD_DESCRIPTION_LENGTH]u16 - win32.GetThreadDescription(t_handle, raw_data(buf_16[:])) - n := utf16.decode_to_utf8(buf_8[:], buf_16[:]) - buf := make([]u8, n, allocator, loc) - - copy(buf[:], buf_8[:]) - - name = transmute(string)buf + buf_16: win32.PWSTR + win32.GetThreadDescription(t_handle, &buf_16) + name = win32.wstring_to_utf8(buf_16, -1, allocator) or_return return } @@ -185,9 +179,8 @@ _set_name :: proc(thread: ^Thread, name: string) { } buf: [_THREAD_DESCRIPTION_LENGTH]u16 - utf16.encode_string(buf[:], name) // _THREAD_DESCRIPTION_LENGTH includes terminating null - buf[len(buf) - 1] = 0 + utf16.encode_string(buf[:len(buf) - 1], name) win32.SetThreadDescription(t_handle, raw_data(buf[:])) }