diff options
author | 2023-02-24 12:24:04 -0800 | |
---|---|---|
committer | 2023-02-24 14:24:04 -0600 | |
commit | f0e5d5457922a2cbdff954b4dc01c879f8e39b3c (patch) | |
tree | 1f6e4a97308a160976f2e00a53ab98f4b903ed98 /src/darwin_c.zig | |
parent | 1c531472c93f9d3a7b491b100803b8c0ad42d0e7 (diff) | |
download | bun-f0e5d5457922a2cbdff954b4dc01c879f8e39b3c.tar.gz bun-f0e5d5457922a2cbdff954b4dc01c879f8e39b3c.tar.zst bun-f0e5d5457922a2cbdff954b4dc01c879f8e39b3c.zip |
Implement `os.cpus` for Darwin (OS X) (#2115)
* adding experimental Mac implementation os os.cpus
* Simplify cpus interfaces
* remove support for osx 10
* Refactor os.cpus implementation
This commit substantially refactors how the Linux and Darwin implementations of
`os.cpus`. The goal is to avoid unnecessary copying and allow broader latitude
in responding to errors per implementation.
* improved comments
* ensure no buffer overrun
* use PROCESSOR_CPU_LOAD_INFO_COUNT; not sure if this is correct
* oh teh noes
* use sliceTo instead of span
* cpu_ticks are uints
Diffstat (limited to 'src/darwin_c.zig')
-rw-r--r-- | src/darwin_c.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/darwin_c.zig b/src/darwin_c.zig index 474e3374f..f2e22c85e 100644 --- a/src/darwin_c.zig +++ b/src/darwin_c.zig @@ -550,6 +550,23 @@ pub fn get_system_loadavg() [3]f64 { }; } +pub const processor_flavor_t = c_int; + +// https://opensource.apple.com/source/xnu/xnu-792/osfmk/mach/processor_info.h.auto.html +pub const PROCESSOR_CPU_LOAD_INFO: processor_flavor_t = 2; +// https://opensource.apple.com/source/xnu/xnu-792/osfmk/mach/machine.h.auto.html +pub const CPU_STATE_MAX = 4; +pub const processor_cpu_load_info = extern struct { + cpu_ticks: [CPU_STATE_MAX]c_uint, +}; +pub const PROCESSOR_CPU_LOAD_INFO_COUNT = @as(std.c.mach_msg_type_number_t, + @sizeOf(processor_cpu_load_info)/@sizeOf(std.c.natural_t)); +pub const processor_info_array_t = [*]c_int; +pub const PROCESSOR_INFO_MAX = 1024; + +pub extern fn host_processor_info(host: std.c.host_t , flavor: processor_flavor_t , out_processor_count: *std.c.natural_t , out_processor_info: *processor_info_array_t, out_processor_infoCnt: *std.c.mach_msg_type_number_t) std.c.E; + + pub extern fn getuid(...) std.os.uid_t; pub extern fn getgid(...) std.os.gid_t; |