Skip to content

Commit

Permalink
Auto merge of #2279 - devnexen:thread_info_apple, r=Amanieu
Browse files Browse the repository at this point in the history
apple thread_info api addition
  • Loading branch information
bors committed Jul 9, 2021
2 parents ba34161 + 4b0b7fd commit 13c8ceb
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,7 @@ THOUSEP
THREAD_BACKGROUND_POLICY
THREAD_BACKGROUND_POLICY_DARWIN_BG
THREAD_BACKGROUND_POLICY_COUNT
THREAD_BASIC_INFO
THREAD_AFFINITY_POLICY
THREAD_AFFINITY_POLICY_COUNT
THREAD_AFFINITY_TAG_NULL
Expand All @@ -1208,6 +1209,14 @@ THREAD_THROUGHPUT_QOS_POLICY
THREAD_THROUGHPUT_QOS_POLICY_COUNT
THREAD_TIME_CONSTRAINT_POLICY
THREAD_TIME_CONSTRAINT_POLICY_COUNT
TH_FLAGS_GLOBAL_FORCED_IDLE
TH_FLAGS_IDLE
TH_FLAGS_SWAPPED
TH_STATE_HALTED
TH_STATE_RUNNING
TH_STATE_STOPPED
TH_STATE_UNINTERRUPTIBLE
TH_STATE_WAITING
TIME_DEL
TIME_ERROR
TIME_INS
Expand Down Expand Up @@ -1731,6 +1740,7 @@ open_wmemstream
openat
openpty
pause
policy_t
popen
posix_madvise
posix_spawn
Expand Down Expand Up @@ -1873,10 +1883,16 @@ sysctl
sysctlbyname
sysctlnametomib
telldir
thread_basic_info_t
thread_flavor_t
thread_info
thread_info_t
thread_inspect_t
thread_policy_set
thread_policy_get
timeval32
timex
time_value_t
truncate
ttyname_r
ucontext_t
Expand Down
100 changes: 100 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub type sae_connid_t = u32;

pub type mach_port_t = ::c_uint;
pub type processor_flavor_t = ::c_int;
pub type thread_flavor_t = natural_t;
pub type thread_inspect_t = mach_port_t;
pub type policy_t = ::c_int;

pub type iconv_t = *mut ::c_void;

Expand All @@ -55,6 +58,9 @@ pub type processor_set_load_info_t = *mut processor_set_load_info;
pub type processor_info_t = *mut integer_t;
pub type processor_info_array_t = *mut integer_t;

pub type thread_info_t = *mut integer_t;
pub type thread_basic_info_t = *mut thread_basic_info;

pub type thread_t = mach_port_t;
pub type thread_policy_flavor_t = natural_t;
pub type thread_policy_t = *mut integer_t;
Expand Down Expand Up @@ -806,6 +812,22 @@ s_no_extra_traits! {
pub load_average: integer_t,
pub mach_factor: integer_t,
}

pub struct time_value_t {
pub seconds: integer_t,
pub microseconds: integer_t,
}

pub struct thread_basic_info {
pub user_time: time_value_t,
pub system_time: time_value_t,
pub cpu_usage: ::integer_t,
pub policy: ::policy_t,
pub run_state: ::integer_t,
pub flags: ::integer_t,
pub suspend_count: ::integer_t,
pub sleep_time: ::integer_t,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -1520,6 +1542,67 @@ cfg_if! {
self.mach_factor.hash(state);
}
}

impl PartialEq for time_value_t {
fn eq(&self, other: &time_value_t) -> bool {
self.seconds == other.seconds
&& self.microseconds == other.microseconds
}
}
impl Eq for time_value_t {}
impl ::fmt::Debug for time_value_t {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("time_value_t")
.field("seconds", &self.seconds)
.field("microseconds", &self.seconds)
.finish()
}
}
impl ::hash::Hash for time_value_t {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.seconds.hash(state);
self.microseconds.hash(state);
}
}
impl PartialEq for thread_basic_info {
fn eq(&self, other: &thread_basic_info) -> bool {
self.user_time == other.user_time
&& self.system_time == other.system_time
&& self.cpu_usage == other.cpu_usage
&& self.policy == other.policy
&& self.run_state == other.run_state
&& self.flags == other.flags
&& self.suspend_count == other.suspend_count
&& self.sleep_time == other.sleep_time
}
}
impl Eq for thread_basic_info {}
impl ::fmt::Debug for thread_basic_info {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("thread_basic_info")
.field("user_time", &self.user_time)
.field("system_time", &self.system_time)
.field("cpu_usage", &self.cpu_usage)
.field("policy", &self.policy)
.field("run_state", &self.run_state)
.field("flags", &self.flags)
.field("suspend_count", &self.suspend_count)
.field("sleep_time", &self.sleep_time)
.finish()
}
}
impl ::hash::Hash for thread_basic_info {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.user_time.hash(state);
self.system_time.hash(state);
self.cpu_usage.hash(state);
self.policy.hash(state);
self.run_state.hash(state);
self.flags.hash(state);
self.suspend_count.hash(state);
self.sleep_time.hash(state);
}
}
}
}

Expand Down Expand Up @@ -3525,6 +3608,17 @@ pub const THREAD_BACKGROUND_POLICY_DARWIN_BG: ::c_int = 0x1000;
pub const THREAD_LATENCY_QOS_POLICY: ::c_int = 7;
pub const THREAD_THROUGHPUT_QOS_POLICY: ::c_int = 8;

// <mach/thread_info.h>
pub const TH_STATE_RUNNING: ::c_int = 1;
pub const TH_STATE_STOPPED: ::c_int = 2;
pub const TH_STATE_WAITING: ::c_int = 3;
pub const TH_STATE_UNINTERRUPTIBLE: ::c_int = 4;
pub const TH_STATE_HALTED: ::c_int = 5;
pub const TH_FLAGS_SWAPPED: ::c_int = 0x1;
pub const TH_FLAGS_IDLE: ::c_int = 0x2;
pub const TH_FLAGS_GLOBAL_FORCED_IDLE: ::c_int = 0x4;
pub const THREAD_BASIC_INFO: ::c_int = 3;

// CommonCrypto/CommonCryptoError.h
pub const kCCSuccess: i32 = 0;
pub const kCCParamError: i32 = -4300;
Expand Down Expand Up @@ -3830,6 +3924,12 @@ extern "C" {
count: *mut mach_msg_type_number_t,
get_default: *mut boolean_t,
) -> kern_return_t;
pub fn thread_info(
target_act: thread_inspect_t,
flavor: thread_flavor_t,
thread_info_out: thread_info_t,
thread_info_outCnt: *mut mach_msg_type_number_t,
) -> kern_return_t;
pub fn __error() -> *mut ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int;
#[cfg_attr(
Expand Down

0 comments on commit 13c8ceb

Please sign in to comment.