| author | |
| committer | |
| log | 05268bb9677ef0545cca6c788169b2707842dc8d |
| tree | e97e926eb065c6853277d6c31d36fa44d65a2986 |
| parent | 87de8212adac280780900f8a68c302c6bc127c47 |
2 files changed, 44 insertions(+), 0 deletions(-)
lib/std/c/freebsd.zig+31| ... | ... | @@ -18,10 +18,41 @@ fn __BIT_COUNT(bits: []const c_long) c_long { |
| 18 | 18 | return count; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | fn __BIT_MASK(s: usize) c_long { | |
| 22 | var x = s % CPU_SETSIZE; | |
| 23 | return @bitCast(c_long, @intCast(c_ulong, 1) << @intCast(u6, x)); | |
| 24 | } | |
| 25 | ||
| 21 | 26 | pub fn CPU_COUNT(set: cpuset_t) c_int { |
| 22 | 27 | return @intCast(c_int, __BIT_COUNT(set.__bits[0..])); |
| 23 | 28 | } |
| 24 | 29 | |
| 30 | pub fn CPU_ZERO(set: *cpuset_t) void { | |
| 31 | @memset((set.*).__bits[0..], 0); | |
| 32 | } | |
| 33 | ||
| 34 | pub fn CPU_SET(cpu: usize, set: *cpuset_t) void { | |
| 35 | const x = cpu / @sizeOf(c_long); | |
| 36 | if (x < @sizeOf(cpuset_t)) { | |
| 37 | (set.*).__bits[x] |= __BIT_MASK(x); | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | pub fn CPU_ISSET(cpu: usize, set: cpuset_t) void { | |
| 42 | const x = cpu / @sizeOf(c_long); | |
| 43 | if (x < @sizeOf(cpuset_t)) { | |
| 44 | return set.__bits[x] & __BIT_MASK(x); | |
| 45 | } | |
| 46 | return false; | |
| 47 | } | |
| 48 | ||
| 49 | pub fn CPU_CLR(cpu: usize, set: *cpuset_t) void { | |
| 50 | const x = cpu / @sizeOf(c_long); | |
| 51 | if (x < @sizeOf(cpuset_t)) { | |
| 52 | (set.*).__bits[x] &= !__BIT_MASK(x); | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 25 | 56 | pub const cpulevel_t = c_int; |
| 26 | 57 | pub const cpuwhich_t = c_int; |
| 27 | 58 | pub const id_t = i64; |
lib/std/os.zig+13| ... | ... | @@ -5573,6 +5573,19 @@ pub fn sched_setaffinity(pid: pid_t, cpus: []usize) SchedSetAffinityError!cpu_se |
| 5573 | 5573 | .PERM => return error.PermissionDenied, |
| 5574 | 5574 | else => |err| return unexpectedErrno(err), |
| 5575 | 5575 | } |
| 5576 | } else if (builtin.os.tag == .freebsd) { | |
| 5577 | freebsd.CPU_ZERO(&set); | |
| 5578 | for (cpus) |cpu| { | |
| 5579 | freebsd.CPU_SET(cpu, &set); | |
| 5580 | } | |
| 5581 | switch (errno(freebsd.cpuset_setaffinity(freebsd.CPU_LEVEL_WHICH, freebsd.CPU_WHICH_PID, pid, @sizeOf(cpu_set_t), &set))) { | |
| 5582 | .SUCCESS => return set, | |
| 5583 | .FAULT => unreachable, | |
| 5584 | .SRCH => unreachable, | |
| 5585 | .INVAL => return error.InvalidCpu, | |
| 5586 | .PERM => return error.PermissionDenied, | |
| 5587 | else => |err| return unexpectedErrno(err), | |
| 5588 | } | |
| 5576 | 5589 | } else { |
| 5577 | 5590 | @compileError("unsupported platform"); |
| 5578 | 5591 | } |