| ... | ... | @@ -85,13 +85,12 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 85 | 85 | defer file.close(); |
| 86 | 86 | |
| 87 | 87 | try file.writer().writeAll(name); |
| 88 | return; |
| 88 | 89 | }, |
| 89 | 90 | .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| { |
| 90 | 91 | // SetThreadDescription is only available since version 1607, which is 10.0.14393.795 |
| 91 | 92 | // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK |
| 92 | | if (!res) { |
| 93 | | return error.Unsupported; |
| 94 | | } |
| 93 | if (!res) return error.Unsupported; |
| 95 | 94 | |
| 96 | 95 | var name_buf_w: [max_name_len:0]u16 = undefined; |
| 97 | 96 | const length = try std.unicode.utf8ToUtf16Le(&name_buf_w, name); |
| ... | ... | @@ -101,8 +100,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 101 | 100 | self.getHandle(), |
| 102 | 101 | @ptrCast(os.windows.LPWSTR, &name_buf_w), |
| 103 | 102 | ); |
| 104 | | } else { |
| 105 | | return error.Unsupported; |
| 103 | return; |
| 106 | 104 | }, |
| 107 | 105 | .macos, .ios, .watchos, .tvos => if (use_pthreads) { |
| 108 | 106 | // There doesn't seem to be a way to set the name for an arbitrary thread, only the current one. |
| ... | ... | @@ -130,6 +128,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 130 | 128 | // pthread_setname_np can return an error. |
| 131 | 129 | |
| 132 | 130 | std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr); |
| 131 | return; |
| 133 | 132 | }, |
| 134 | 133 | .dragonfly => if (use_pthreads) { |
| 135 | 134 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); |
| ... | ... | @@ -142,8 +141,9 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 142 | 141 | else => |e| return os.unexpectedErrno(e), |
| 143 | 142 | } |
| 144 | 143 | }, |
| 145 | | else => return error.Unsupported, |
| 144 | else => {}, |
| 146 | 145 | } |
| 146 | return error.Unsupported; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | pub const GetNameError = error{ |
| ... | ... | @@ -193,9 +193,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 193 | 193 | .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| { |
| 194 | 194 | // GetThreadDescription is only available since version 1607, which is 10.0.14393.795 |
| 195 | 195 | // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK |
| 196 | | if (!res) { |
| 197 | | return error.Unsupported; |
| 198 | | } |
| 196 | if (!res) return error.Unsupported; |
| 199 | 197 | |
| 200 | 198 | var name_w: os.windows.LPWSTR = undefined; |
| 201 | 199 | try os.windows.GetThreadDescription(self.getHandle(), &name_w); |
| ... | ... | @@ -204,8 +202,6 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 204 | 202 | const data_len = try std.unicode.utf16leToUtf8(buffer, std.mem.sliceTo(name_w, 0)); |
| 205 | 203 | |
| 206 | 204 | return if (data_len >= 1) buffer[0..data_len] else null; |
| 207 | | } else { |
| 208 | | return error.Unsupported; |
| 209 | 205 | }, |
| 210 | 206 | .macos, .ios, .watchos, .tvos => if (use_pthreads) { |
| 211 | 207 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); |
| ... | ... | @@ -241,8 +237,9 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 241 | 237 | else => |e| return os.unexpectedErrno(e), |
| 242 | 238 | } |
| 243 | 239 | }, |
| 244 | | else => return error.Unsupported, |
| 240 | else => {}, |
| 245 | 241 | } |
| 242 | return error.Unsupported; |
| 246 | 243 | } |
| 247 | 244 | |
| 248 | 245 | /// Represents a unique ID per thread. |