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

dragonfly: port std.Thread.setname/getname


2 files changed, 25 insertions(+), 0 deletions(-)

lib/std/Thread.zig+22
...@@ -41,6 +41,7 @@ pub const max_name_len = switch (target.os.tag) {...@@ -41,6 +41,7 @@ pub const max_name_len = switch (target.os.tag) {
41 .netbsd => 31,41 .netbsd => 31,
42 .freebsd => 15,42 .freebsd => 15,
43 .openbsd => 31,43 .openbsd => 31,
44 .dragonfly => 1023,
44 .solaris => 31,45 .solaris => 31,
45 else => 0,46 else => 0,
46};47};
...@@ -130,6 +131,17 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {...@@ -130,6 +131,17 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
130131
131 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);132 std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
132 },133 },
134 .dragonfly => if (use_pthreads) {
135 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
136 switch (err) {
137 .SUCCESS => return,
138 .INVAL => unreachable,
139 .FAULT => unreachable,
140 .NAMETOOLONG => unreachable, // already checked
141 .SRCH => unreachable,
142 else => |e| return os.unexpectedErrno(e),
143 }
144 },
133 else => return error.Unsupported,145 else => return error.Unsupported,
134 }146 }
135}147}
...@@ -219,6 +231,16 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co...@@ -219,6 +231,16 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
219 std.c.pthread_get_name_np(self.getHandle(), buffer.ptr, max_name_len + 1);231 std.c.pthread_get_name_np(self.getHandle(), buffer.ptr, max_name_len + 1);
220 return std.mem.sliceTo(buffer, 0);232 return std.mem.sliceTo(buffer, 0);
221 },233 },
234 .dragonfly => if (use_pthreads) {
235 const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
236 switch (err) {
237 .SUCCESS => return std.mem.sliceTo(buffer, 0),
238 .INVAL => unreachable,
239 .FAULT => unreachable,
240 .SRCH => unreachable,
241 else => |e| return os.unexpectedErrno(e),
242 }
243 },
222 else => return error.Unsupported,244 else => return error.Unsupported,
223 }245 }
224}246}
lib/std/c/dragonfly.zig+3
...@@ -33,6 +33,9 @@ pub const pthread_attr_t = extern struct { // copied from freebsd...@@ -33,6 +33,9 @@ pub const pthread_attr_t = extern struct { // copied from freebsd
3333
34pub const sem_t = ?*opaque {};34pub const sem_t = ?*opaque {};
3535
36pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
37pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
38
36// See:39// See:
37// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h40// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
38// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h41// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h