Skip to content

Commit 13c8ceb

Browse files
committed
Auto merge of #2279 - devnexen:thread_info_apple, r=Amanieu
apple thread_info api addition
2 parents ba34161 + 4b0b7fd commit 13c8ceb

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

libc-test/semver/apple.txt

+16
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ THOUSEP
11931193
THREAD_BACKGROUND_POLICY
11941194
THREAD_BACKGROUND_POLICY_DARWIN_BG
11951195
THREAD_BACKGROUND_POLICY_COUNT
1196+
THREAD_BASIC_INFO
11961197
THREAD_AFFINITY_POLICY
11971198
THREAD_AFFINITY_POLICY_COUNT
11981199
THREAD_AFFINITY_TAG_NULL
@@ -1208,6 +1209,14 @@ THREAD_THROUGHPUT_QOS_POLICY
12081209
THREAD_THROUGHPUT_QOS_POLICY_COUNT
12091210
THREAD_TIME_CONSTRAINT_POLICY
12101211
THREAD_TIME_CONSTRAINT_POLICY_COUNT
1212+
TH_FLAGS_GLOBAL_FORCED_IDLE
1213+
TH_FLAGS_IDLE
1214+
TH_FLAGS_SWAPPED
1215+
TH_STATE_HALTED
1216+
TH_STATE_RUNNING
1217+
TH_STATE_STOPPED
1218+
TH_STATE_UNINTERRUPTIBLE
1219+
TH_STATE_WAITING
12111220
TIME_DEL
12121221
TIME_ERROR
12131222
TIME_INS
@@ -1731,6 +1740,7 @@ open_wmemstream
17311740
openat
17321741
openpty
17331742
pause
1743+
policy_t
17341744
popen
17351745
posix_madvise
17361746
posix_spawn
@@ -1873,10 +1883,16 @@ sysctl
18731883
sysctlbyname
18741884
sysctlnametomib
18751885
telldir
1886+
thread_basic_info_t
1887+
thread_flavor_t
1888+
thread_info
1889+
thread_info_t
1890+
thread_inspect_t
18761891
thread_policy_set
18771892
thread_policy_get
18781893
timeval32
18791894
timex
1895+
time_value_t
18801896
truncate
18811897
ttyname_r
18821898
ucontext_t

src/unix/bsd/apple/mod.rs

+100
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub type sae_connid_t = u32;
4141

4242
pub type mach_port_t = ::c_uint;
4343
pub type processor_flavor_t = ::c_int;
44+
pub type thread_flavor_t = natural_t;
45+
pub type thread_inspect_t = mach_port_t;
46+
pub type policy_t = ::c_int;
4447

4548
pub type iconv_t = *mut ::c_void;
4649

@@ -55,6 +58,9 @@ pub type processor_set_load_info_t = *mut processor_set_load_info;
5558
pub type processor_info_t = *mut integer_t;
5659
pub type processor_info_array_t = *mut integer_t;
5760

61+
pub type thread_info_t = *mut integer_t;
62+
pub type thread_basic_info_t = *mut thread_basic_info;
63+
5864
pub type thread_t = mach_port_t;
5965
pub type thread_policy_flavor_t = natural_t;
6066
pub type thread_policy_t = *mut integer_t;
@@ -806,6 +812,22 @@ s_no_extra_traits! {
806812
pub load_average: integer_t,
807813
pub mach_factor: integer_t,
808814
}
815+
816+
pub struct time_value_t {
817+
pub seconds: integer_t,
818+
pub microseconds: integer_t,
819+
}
820+
821+
pub struct thread_basic_info {
822+
pub user_time: time_value_t,
823+
pub system_time: time_value_t,
824+
pub cpu_usage: ::integer_t,
825+
pub policy: ::policy_t,
826+
pub run_state: ::integer_t,
827+
pub flags: ::integer_t,
828+
pub suspend_count: ::integer_t,
829+
pub sleep_time: ::integer_t,
830+
}
809831
}
810832

811833
impl siginfo_t {
@@ -1520,6 +1542,67 @@ cfg_if! {
15201542
self.mach_factor.hash(state);
15211543
}
15221544
}
1545+
1546+
impl PartialEq for time_value_t {
1547+
fn eq(&self, other: &time_value_t) -> bool {
1548+
self.seconds == other.seconds
1549+
&& self.microseconds == other.microseconds
1550+
}
1551+
}
1552+
impl Eq for time_value_t {}
1553+
impl ::fmt::Debug for time_value_t {
1554+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1555+
f.debug_struct("time_value_t")
1556+
.field("seconds", &self.seconds)
1557+
.field("microseconds", &self.seconds)
1558+
.finish()
1559+
}
1560+
}
1561+
impl ::hash::Hash for time_value_t {
1562+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1563+
self.seconds.hash(state);
1564+
self.microseconds.hash(state);
1565+
}
1566+
}
1567+
impl PartialEq for thread_basic_info {
1568+
fn eq(&self, other: &thread_basic_info) -> bool {
1569+
self.user_time == other.user_time
1570+
&& self.system_time == other.system_time
1571+
&& self.cpu_usage == other.cpu_usage
1572+
&& self.policy == other.policy
1573+
&& self.run_state == other.run_state
1574+
&& self.flags == other.flags
1575+
&& self.suspend_count == other.suspend_count
1576+
&& self.sleep_time == other.sleep_time
1577+
}
1578+
}
1579+
impl Eq for thread_basic_info {}
1580+
impl ::fmt::Debug for thread_basic_info {
1581+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1582+
f.debug_struct("thread_basic_info")
1583+
.field("user_time", &self.user_time)
1584+
.field("system_time", &self.system_time)
1585+
.field("cpu_usage", &self.cpu_usage)
1586+
.field("policy", &self.policy)
1587+
.field("run_state", &self.run_state)
1588+
.field("flags", &self.flags)
1589+
.field("suspend_count", &self.suspend_count)
1590+
.field("sleep_time", &self.sleep_time)
1591+
.finish()
1592+
}
1593+
}
1594+
impl ::hash::Hash for thread_basic_info {
1595+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1596+
self.user_time.hash(state);
1597+
self.system_time.hash(state);
1598+
self.cpu_usage.hash(state);
1599+
self.policy.hash(state);
1600+
self.run_state.hash(state);
1601+
self.flags.hash(state);
1602+
self.suspend_count.hash(state);
1603+
self.sleep_time.hash(state);
1604+
}
1605+
}
15231606
}
15241607
}
15251608

@@ -3525,6 +3608,17 @@ pub const THREAD_BACKGROUND_POLICY_DARWIN_BG: ::c_int = 0x1000;
35253608
pub const THREAD_LATENCY_QOS_POLICY: ::c_int = 7;
35263609
pub const THREAD_THROUGHPUT_QOS_POLICY: ::c_int = 8;
35273610

3611+
// <mach/thread_info.h>
3612+
pub const TH_STATE_RUNNING: ::c_int = 1;
3613+
pub const TH_STATE_STOPPED: ::c_int = 2;
3614+
pub const TH_STATE_WAITING: ::c_int = 3;
3615+
pub const TH_STATE_UNINTERRUPTIBLE: ::c_int = 4;
3616+
pub const TH_STATE_HALTED: ::c_int = 5;
3617+
pub const TH_FLAGS_SWAPPED: ::c_int = 0x1;
3618+
pub const TH_FLAGS_IDLE: ::c_int = 0x2;
3619+
pub const TH_FLAGS_GLOBAL_FORCED_IDLE: ::c_int = 0x4;
3620+
pub const THREAD_BASIC_INFO: ::c_int = 3;
3621+
35283622
// CommonCrypto/CommonCryptoError.h
35293623
pub const kCCSuccess: i32 = 0;
35303624
pub const kCCParamError: i32 = -4300;
@@ -3830,6 +3924,12 @@ extern "C" {
38303924
count: *mut mach_msg_type_number_t,
38313925
get_default: *mut boolean_t,
38323926
) -> kern_return_t;
3927+
pub fn thread_info(
3928+
target_act: thread_inspect_t,
3929+
flavor: thread_flavor_t,
3930+
thread_info_out: thread_info_t,
3931+
thread_info_outCnt: *mut mach_msg_type_number_t,
3932+
) -> kern_return_t;
38333933
pub fn __error() -> *mut ::c_int;
38343934
pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int;
38353935
#[cfg_attr(

0 commit comments

Comments
 (0)