Skip to content

Commit 4bfd37d

Browse files
devnexenVexu
authored andcommitted
std.c: adding cpu affinity api for macOs (mainly x86_64)
1 parent d70853b commit 4bfd37d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/std/c/darwin.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,3 +3896,23 @@ pub const MIN = struct {
38963896

38973897
pub extern "c" fn mincore(addr: *align(std.mem.page_size) const anyopaque, length: usize, vec: [*]u8) c_int;
38983898
pub extern "c" fn os_proc_available_memory() usize;
3899+
3900+
pub const thread_affinity_policy = extern struct {
3901+
tag: integer_t,
3902+
};
3903+
3904+
pub const thread_policy_flavor_t = natural_t;
3905+
pub const thread_policy_t = [*]integer_t;
3906+
pub const thread_affinity_policy_data_t = thread_affinity_policy;
3907+
pub const thread_affinity_policy_t = [*]thread_affinity_policy;
3908+
3909+
pub const THREAD_AFFINITY = struct {
3910+
pub const POLICY = 0;
3911+
pub const POLICY_COUNT = @intCast(mach_msg_type_number_t, @sizeOf(thread_affinity_policy_data_t) / @sizeOf(integer_t));
3912+
};
3913+
3914+
/// cpu affinity api
3915+
/// albeit it is also available on arm64, it always fails as in this architecture there is no sense of
3916+
/// individual cpus (high performance cpus group and low consumption one), thus the pthread QOS api is more appropriate in this case.
3917+
pub extern "c" fn thread_affinity_get(thread: thread_act_t, flavor: thread_policy_flavor_t, info: thread_policy_t, infocnt: [*]mach_msg_type_number_t, default: *boolean_t) kern_return_t;
3918+
pub extern "c" fn thread_affinity_set(thread: thread_act_t, flavor: thread_policy_flavor_t, info: thread_policy_t, infocnt: mach_msg_type_number_t) kern_return_t;

0 commit comments

Comments
 (0)