Skip to content

Commit

Permalink
Add host_cpu_load_info on Apple
Browse files Browse the repository at this point in the history
Snippet from `host_info.h`:

```
struct host_cpu_load_info {             /* number of ticks while running... */
    natural_t       cpu_ticks[CPU_STATE_MAX]; /* ... in the given mode */
};

typedef struct host_cpu_load_info       host_cpu_load_info_data_t;
typedef struct host_cpu_load_info       *host_cpu_load_info_t;
```
  • Loading branch information
stepancheg committed Sep 11, 2024
1 parent 2c0250f commit 65efdc3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,9 @@ getxattr
glob
glob_t
globfree
host_cpu_load_info
host_cpu_load_info_data_t
host_cpu_load_info_t
icmp6_ifstat
iconv_t
id_t
Expand Down
28 changes: 28 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub type ledger_array_t = *mut ::ledger_t;

pub type iconv_t = *mut ::c_void;

// mach/host_info.h
pub type host_cpu_load_info_t = *mut host_cpu_load_info;
pub type host_cpu_load_info_data_t = host_cpu_load_info;

// mach/processor_info.h
pub type processor_cpu_load_info_t = *mut processor_cpu_load_info;
pub type processor_cpu_load_info_data_t = processor_cpu_load_info;
pub type processor_basic_info_t = *mut processor_basic_info;
Expand Down Expand Up @@ -1338,6 +1343,10 @@ s_no_extra_traits! {
pub sigev_notify_attributes: *mut ::pthread_attr_t
}

pub struct host_cpu_load_info {
pub cpu_ticks: [::natural_t; CPU_STATE_MAX as usize],
}

pub struct processor_cpu_load_info {
pub cpu_ticks: [::c_uint; CPU_STATE_MAX as usize],
}
Expand Down Expand Up @@ -2180,6 +2189,25 @@ cfg_if! {
}
}

impl PartialEq for host_cpu_load_info {
fn eq(&self, other: &host_cpu_load_info) -> bool {
self.cpu_ticks == other.cpu_ticks
}
}
impl Eq for host_cpu_load_info {}
impl ::fmt::Debug for host_cpu_load_info {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("host_cpu_load_info")
.field("cpu_ticks", &self.cpu_ticks)
.finish()
}
}
impl ::hash::Hash for host_cpu_load_info {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.cpu_ticks.hash(state);
}
}

impl PartialEq for processor_cpu_load_info {
fn eq(&self, other: &processor_cpu_load_info) -> bool {
self.cpu_ticks == other.cpu_ticks
Expand Down

0 comments on commit 65efdc3

Please sign in to comment.