mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
dragonfly: port std.Thread.setname/getname
This commit is contained in:
parent
601ac82041
commit
d621f4322b
@ -41,6 +41,7 @@ pub const max_name_len = switch (target.os.tag) {
|
||||
.netbsd => 31,
|
||||
.freebsd => 15,
|
||||
.openbsd => 31,
|
||||
.dragonfly => 1023,
|
||||
.solaris => 31,
|
||||
else => 0,
|
||||
};
|
||||
@ -130,6 +131,17 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
|
||||
|
||||
std.c.pthread_set_name_np(self.getHandle(), name_with_terminator.ptr);
|
||||
},
|
||||
.dragonfly => if (use_pthreads) {
|
||||
const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
|
||||
switch (err) {
|
||||
.SUCCESS => return,
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.NAMETOOLONG => unreachable, // already checked
|
||||
.SRCH => unreachable,
|
||||
else => |e| return os.unexpectedErrno(e),
|
||||
}
|
||||
},
|
||||
else => return error.Unsupported,
|
||||
}
|
||||
}
|
||||
@ -219,6 +231,16 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
|
||||
std.c.pthread_get_name_np(self.getHandle(), buffer.ptr, max_name_len + 1);
|
||||
return std.mem.sliceTo(buffer, 0);
|
||||
},
|
||||
.dragonfly => if (use_pthreads) {
|
||||
const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1);
|
||||
switch (err) {
|
||||
.SUCCESS => return std.mem.sliceTo(buffer, 0),
|
||||
.INVAL => unreachable,
|
||||
.FAULT => unreachable,
|
||||
.SRCH => unreachable,
|
||||
else => |e| return os.unexpectedErrno(e),
|
||||
}
|
||||
},
|
||||
else => return error.Unsupported,
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,9 @@ pub const pthread_attr_t = extern struct { // copied from freebsd
|
||||
|
||||
pub const sem_t = ?*opaque {};
|
||||
|
||||
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
|
||||
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
|
||||
|
||||
// See:
|
||||
// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/include/unistd.h
|
||||
// - https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/sys/types.h
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user