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 {
8585 defer file.close();
8686
8787 try file.writer().writeAll(name);
88 return;
8889 },
8990 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
9091 // SetThreadDescription is only available since version 1607, which is 10.0.14393.795
9192 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
92 if (!res) {
93 return error.Unsupported;
94 }
93 if (!res) return error.Unsupported;
9594
9695 var name_buf_w: [max_name_len:0]u16 = undefined;
9796 const length = try std.unicode.utf8ToUtf16Le(&name_buf_w, name);
......@@ -101,8 +100,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
101100 self.getHandle(),
102101 @ptrCast(os.windows.LPWSTR, &name_buf_w),
103102 );
104 } else {
105 return error.Unsupported;
103 return;
106104 },
107105 .macos, .ios, .watchos, .tvos => if (use_pthreads) {
108106 // 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 {
130128 // pthread_setname_np can return an error.
131129
132130 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
131 return;
133132 },
134133 .dragonfly => if (use_pthreads) {
135134 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 {
142141 else => |e| return os.unexpectedErrno(e),
143142 }
144143 },
145 else => return error.Unsupported,
144 else => {},
146145 }
146 return error.Unsupported;
147147}
148148
149149pub const GetNameError = error{
......@@ -193,9 +193,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
193193 .windows => if (target.os.isAtLeast(.windows, .win10_rs1)) |res| {
194194 // GetThreadDescription is only available since version 1607, which is 10.0.14393.795
195195 // See https://en.wikipedia.org/wiki/Microsoft_Windows_SDK
196 if (!res) {
197 return error.Unsupported;
198 }
196 if (!res) return error.Unsupported;
199197
200198 var name_w: os.windows.LPWSTR = undefined;
201199 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
204202 const data_len = try std.unicode.utf16leToUtf8(buffer, std.mem.sliceTo(name_w, 0));
205203
206204 return if (data_len >= 1) buffer[0..data_len] else null;
207 } else {
208 return error.Unsupported;
209205 },
210206 .macos, .ios, .watchos, .tvos => if (use_pthreads) {
211207 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
241237 else => |e| return os.unexpectedErrno(e),
242238 }
243239 },
244 else => return error.Unsupported,
240 else => {},
245241 }
242 return error.Unsupported;
246243}
247244
248245/// Represents a unique ID per thread.