authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2025-11-28 17:26:43+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-25 08:10:25+01:00
log8f6bad065e1661c67520775ffab88e6f135e00f7
tree4825a3fb473e0f8632e67b32eae5aec70ce16216
parent4431ca28b86b2e8efad4a6340e0eac07f5a09ac5

std.Thread.setName/getName: remove wrong error handling

std.posix.prctl already does error handling. According to the man page PR_SET_NAME(2const), 0 is returned on success.

1 files changed, 4 insertions(+), 10 deletions(-)

lib/std/Thread.zig+4-10
......@@ -63,11 +63,8 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
6363 .linux => if (use_pthreads) {
6464 if (self.getHandle() == std.c.pthread_self()) {
6565 // Set the name of the calling thread (no thread id required).
66 const err = try posix.prctl(.SET_NAME, .{@intFromPtr(name_with_terminator.ptr)});
67 switch (@as(posix.E, @enumFromInt(err))) {
68 .SUCCESS => return,
69 else => |e| return posix.unexpectedErrno(e),
70 }
66 assert(try posix.prctl(.SET_NAME, .{@intFromPtr(name_with_terminator.ptr)}) == 0);
67 return;
7168 } else {
7269 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
7370 switch (@as(posix.E, @enumFromInt(err))) {
......@@ -167,11 +164,8 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
167164 .linux => if (use_pthreads) {
168165 if (self.getHandle() == std.c.pthread_self()) {
169166 // Get the name of the calling thread (no thread id required).
170 const err = try posix.prctl(.GET_NAME, .{@intFromPtr(buffer.ptr)});
171 switch (@as(posix.E, @enumFromInt(err))) {
172 .SUCCESS => return std.mem.sliceTo(buffer, 0),
173 else => |e| return posix.unexpectedErrno(e),
174 }
167 assert(try posix.prctl(.GET_NAME, .{@intFromPtr(buffer.ptr)}) == 0);
168 return std.mem.sliceTo(buffer, 0);
175169 } else {
176170 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
177171 switch (@as(posix.E, @enumFromInt(err))) {