authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-10-07 14:31:06-04:00
committergravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2021-10-09 03:52:28-04:00
loge376fab186e7ff94808fd0cd88161f7345211a07
tree6fcf67a03e4439c8977762f2a711c349446240ee
parentd621f4322b351817b6fdb058b264adb329c54fdb
signaturelock-open Commit is signed but in an unrecognized format.

housekeeping: return error.Unsupported

Return error at end of std.Thread.setName/getName to simplify flow-control.

1 files changed, 9 insertions(+), 12 deletions(-)

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