mirror of
https://github.com/ziglang/zig.git
synced 2026-01-05 21:13:24 +00:00
os: expand sched_getaffinity wrapper and update freebsd's cpuset api flags.
This commit is contained in:
parent
0282c2a924
commit
dbdafb6cc5
@ -13,6 +13,19 @@ pub const cpulevel_t = c_int;
|
||||
pub const cpuwhich_t = c_int;
|
||||
pub const id_t = i64;
|
||||
|
||||
pub const CPU_LEVEL_ROOT: cpulevel_t = 1;
|
||||
pub const CPU_LEVEL_CPUSET: cpulevel_t = 2;
|
||||
pub const CPU_LEVEL_WHICH: cpulevel_t = 3;
|
||||
pub const CPU_WHICH_TID: cpuwhich_t = 1;
|
||||
pub const CPU_WHICH_PID: cpuwhich_t = 2;
|
||||
pub const CPU_WHICH_CPUSET: cpuwhich_t = 3;
|
||||
pub const CPU_WHICH_IRQ: cpuwhich_t = 4;
|
||||
pub const CPU_WHICH_JAIL: cpuwhich_t = 5;
|
||||
pub const CPU_WHICH_DOMAIN: cpuwhich_t = 6;
|
||||
pub const CPU_WHICH_INTRHANDLER: cpuwhich_t = 7;
|
||||
pub const CPU_WHICH_ITHREAD: cpuwhich_t = 8;
|
||||
pub const CPU_WHICH_TIDPID: cpuwhich_t = 8;
|
||||
|
||||
extern "c" fn __error() *c_int;
|
||||
pub const _errno = __error;
|
||||
|
||||
|
||||
@ -141,7 +141,12 @@ pub const addrinfo = system.addrinfo;
|
||||
pub const blkcnt_t = system.blkcnt_t;
|
||||
pub const blksize_t = system.blksize_t;
|
||||
pub const clock_t = system.clock_t;
|
||||
pub const cpu_set_t = system.cpu_set_t;
|
||||
pub const cpu_set_t = if (builtin.os.tag == .linux)
|
||||
system.cpu_set_t
|
||||
else if (builtin.os.tag == .freebsd)
|
||||
freebsd.cpuset_t
|
||||
else
|
||||
u32;
|
||||
pub const dev_t = system.dev_t;
|
||||
pub const dl_phdr_info = system.dl_phdr_info;
|
||||
pub const empty_sigset = system.empty_sigset;
|
||||
@ -5518,13 +5523,27 @@ pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError;
|
||||
|
||||
pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t {
|
||||
var set: cpu_set_t = undefined;
|
||||
switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
|
||||
.SUCCESS => return set,
|
||||
.FAULT => unreachable,
|
||||
.INVAL => unreachable,
|
||||
.SRCH => unreachable,
|
||||
.PERM => return error.PermissionDenied,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
if (builtin.os.tag == .linux) {
|
||||
switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) {
|
||||
.SUCCESS => return set,
|
||||
.FAULT => unreachable,
|
||||
.INVAL => unreachable,
|
||||
.SRCH => unreachable,
|
||||
.PERM => return error.PermissionDenied,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
} else if (builtin.os.tag == .freebsd) {
|
||||
switch (errno(freebsd.cpuset_getaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) {
|
||||
.SUCCESS => return set,
|
||||
.FAULT => unreachable,
|
||||
.INVAL => unreachable,
|
||||
.SRCH => unreachable,
|
||||
.EDEADLK => unreachable,
|
||||
.PERM => return error.PermissionDenied,
|
||||
else => |err| return unexpectedErrno(err),
|
||||
}
|
||||
} else {
|
||||
@compileError("unsupported platform");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user