Commit 140ca67ea6

r00ster91 <r00ster91@proton.me>
2023-02-24 20:58:36
std.Thread: use pthread_getname_np on musl
Starting with version 1.2.3, musl now supports pthread_getname_np: https://github.com/bminor/musl/blob/7a43f6fea9081bdd53d8a11cef9e9fab0348c53d/WHATSNEW#L2293-L2329
1 parent f10100c
Changed files (1)
lib
lib/std/Thread.zig
@@ -179,10 +179,6 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
                     else => |e| return os.unexpectedErrno(e),
                 }
             } else {
-                if (target.abi.isMusl()) {
-                    // musl doesn't provide pthread_getname_np and there's no way to retrieve the thread id of an arbitrary thread.
-                    return error.Unsupported;
-                }
                 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
                 switch (err) {
                     .SUCCESS => return std.mem.sliceTo(buffer, 0),
@@ -1133,16 +1129,7 @@ test "setName, getName" {
             error.Unsupported => return error.SkipZigTest,
             else => return err,
         },
-        else => |tag| if (tag == .linux and use_pthreads and comptime target.abi.isMusl()) {
-            try thread.setName("foobar");
-
-            var name_buffer: [max_name_len:0]u8 = undefined;
-            const res = thread.getName(&name_buffer);
-
-            try std.testing.expectError(error.Unsupported, res);
-        } else {
-            try testThreadName(&thread);
-        },
+        else => try testThreadName(&thread),
     }
 
     context.thread_done_event.set();