std.c: adding freebsd's CPU_COUNT macro portage.

This commit is contained in:
David CARLIER
2023-05-02 20:16:19 +01:00
committed by Veikka Tuominen
parent 152c7b1885
commit b9841750f9

View File

@@ -9,6 +9,20 @@ pub const CPU_SETSIZE = 256;
pub const cpuset_t = extern struct {
__bits: [(CPU_SETSIZE + (@bitSizeOf(c_long) - 1)) / @bitSizeOf(c_long)]c_long,
};
// TODO: can eventually serve for the domainset_t's type too.
fn __BIT_COUNT(bits: []const c_long) c_long {
var count: c_long = 0;
for (bits) |b| {
count += @popCount(b);
}
return count;
}
pub fn CPU_COUNT(set: cpuset_t) c_int {
return @intCast(c_int, __BIT_COUNT(set.__bits[0..]));
}
pub const cpulevel_t = c_int;
pub const cpuwhich_t = c_int;
pub const id_t = i64;