mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-01 03:38:55 +00:00
more sensible allocation and fix comment
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user