@@ -41,6 +41,9 @@ pub type sae_connid_t = u32;
41
41
42
42
pub type mach_port_t = :: c_uint ;
43
43
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 ;
44
47
45
48
pub type iconv_t = * mut :: c_void ;
46
49
@@ -55,6 +58,9 @@ pub type processor_set_load_info_t = *mut processor_set_load_info;
55
58
pub type processor_info_t = * mut integer_t ;
56
59
pub type processor_info_array_t = * mut integer_t ;
57
60
61
+ pub type thread_info_t = * mut integer_t ;
62
+ pub type thread_basic_info_t = * mut thread_basic_info ;
63
+
58
64
pub type thread_t = mach_port_t ;
59
65
pub type thread_policy_flavor_t = natural_t ;
60
66
pub type thread_policy_t = * mut integer_t ;
@@ -806,6 +812,22 @@ s_no_extra_traits! {
806
812
pub load_average: integer_t,
807
813
pub mach_factor: integer_t,
808
814
}
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
+ }
809
831
}
810
832
811
833
impl siginfo_t {
@@ -1520,6 +1542,67 @@ cfg_if! {
1520
1542
self . mach_factor. hash( state) ;
1521
1543
}
1522
1544
}
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
+ }
1523
1606
}
1524
1607
}
1525
1608
@@ -3525,6 +3608,17 @@ pub const THREAD_BACKGROUND_POLICY_DARWIN_BG: ::c_int = 0x1000;
3525
3608
pub const THREAD_LATENCY_QOS_POLICY : :: c_int = 7 ;
3526
3609
pub const THREAD_THROUGHPUT_QOS_POLICY : :: c_int = 8 ;
3527
3610
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
+
3528
3622
// CommonCrypto/CommonCryptoError.h
3529
3623
pub const kCCSuccess: i32 = 0 ;
3530
3624
pub const kCCParamError: i32 = -4300 ;
@@ -3830,6 +3924,12 @@ extern "C" {
3830
3924
count : * mut mach_msg_type_number_t ,
3831
3925
get_default : * mut boolean_t ,
3832
3926
) -> 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 ;
3833
3933
pub fn __error ( ) -> * mut :: c_int ;
3834
3934
pub fn backtrace ( buf : * mut * mut :: c_void , sz : :: c_int ) -> :: c_int ;
3835
3935
#[ cfg_attr(
0 commit comments