mach_sys/
thread_policy.rs

1//! This module corresponds to `mach/thread_policy.h`.
2
3use core::mem::size_of;
4
5use crate::boolean::boolean_t;
6use crate::kern_return::kern_return_t;
7use crate::mach_types::thread_t;
8use crate::message::mach_msg_type_number_t;
9use crate::vm_types::{integer_t, natural_t};
10
11pub type thread_policy_t        = *mut integer_t;
12pub type thread_policy_flavor_t = natural_t;
13
14pub const THREAD_STANDARD_POLICY:        thread_policy_flavor_t = 1;
15pub const THREAD_EXTENDED_POLICY:        thread_policy_flavor_t = 1;
16pub const THREAD_TIME_CONSTRAINT_POLICY: thread_policy_flavor_t = 2;
17pub const THREAD_PRECEDENCE_POLICY:      thread_policy_flavor_t = 3;
18pub const THREAD_AFFINITY_POLICY:        thread_policy_flavor_t = 4;
19pub const THREAD_BACKGROUND_POLICY:      thread_policy_flavor_t = 5;
20pub const THREAD_LATENCY_QOS_POLICY:     thread_policy_flavor_t = 7;
21pub const THREAD_THROUGHPUT_QOS_POLICY:  thread_policy_flavor_t = 8;
22
23#[repr(C)]
24#[derive(Clone, Copy, Debug)]
25pub struct thread_standard_policy_t {
26    pub no_data: natural_t,
27}
28pub type thread_standard_policy        = thread_standard_policy_t;
29pub type thread_standard_policy_data_t = thread_standard_policy_t;
30pub const THREAD_STANDARD_POLICY_COUNT: mach_msg_type_number_t = 0;
31
32#[repr(C)]
33#[derive(Clone, Copy, Debug)]
34pub struct thread_extended_policy_t {
35    pub timeshare: boolean_t,
36}
37pub type thread_extended_policy        = thread_extended_policy_t;
38pub type thread_extended_policy_data_t = thread_extended_policy_t;
39pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
40    ( size_of::<thread_extended_policy_t>() / size_of::<integer_t>() ) as _;
41
42#[repr(C)]
43#[derive(Clone, Copy, Debug)]
44pub struct thread_time_constraint_policy_t {
45    pub period:      u32,
46    pub computation: u32,
47    pub constraint:  u32,
48    pub preemptible: boolean_t,
49}
50pub type thread_time_constraint_policy        = thread_time_constraint_policy_t;
51pub type thread_time_constraint_policy_data_t = thread_time_constraint_policy_t;
52pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
53    ( size_of::<thread_time_constraint_policy_t>() / size_of::<integer_t>() ) as _;
54
55#[repr(C)]
56#[derive(Clone, Copy, Debug)]
57pub struct thread_precedence_policy_t {
58    pub importance: integer_t,
59}
60pub type thread_precedence_policy        = thread_precedence_policy_t;
61pub type thread_precedence_policy_data_t = thread_precedence_policy_t;
62pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
63    ( size_of::<thread_precedence_policy_t>() / size_of::<integer_t>() ) as _;
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug)]
67pub struct thread_affinity_policy_t {
68    pub affinity_tag: integer_t,
69}
70pub const THREAD_AFFINITY_TAG_NULL: integer_t = 0;
71pub type thread_affinity_policy        = thread_affinity_policy_t;
72pub type thread_affinity_policy_data_t = thread_affinity_policy_t;
73pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
74    ( size_of::<thread_affinity_policy_t>() / size_of::<integer_t>() ) as _;
75
76#[repr(C)]
77#[derive(Clone, Copy, Debug)]
78pub struct thread_background_policy_t {
79    pub priority: integer_t,
80}
81pub type thread_background_policy        = thread_background_policy_t;
82pub type thread_background_policy_data_t = thread_background_policy_t;
83pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
84    ( size_of::<thread_background_policy_t>() / size_of::<integer_t>() ) as _;
85
86#[repr(C)]
87#[derive(Clone, Copy, Debug)]
88pub struct thread_latency_qos_policy_t {
89    pub thread_latency_qos_tier: thread_latency_qos_t,
90}
91pub type thread_latency_qos_t = integer_t;
92pub type thread_latency_qos_policy        = thread_latency_qos_policy_t;
93pub type thread_latency_qos_policy_data_t = thread_latency_qos_policy_t;
94pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
95    ( size_of::<thread_latency_qos_policy_t>() / size_of::<integer_t>() ) as _;
96
97#[repr(C)]
98#[derive(Clone, Copy, Debug)]
99pub struct thread_throughput_qos_policy_t {
100    pub thread_throughput_qos_tier: thread_throughput_qos_t,
101}
102pub type thread_throughput_qos_t = integer_t;
103pub type thread_throughput_qos_policy         = thread_throughput_qos_policy_t;
104pub type thread_throughput_qos_policy_data_t  = thread_throughput_qos_policy_t;
105pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
106    ( size_of::<thread_throughput_qos_policy_t>() / size_of::<integer_t>() ) as _;
107
108extern "C" {
109    pub fn thread_policy_set(
110        thread: thread_t,
111        flavor: thread_policy_flavor_t,
112        policy_info: thread_policy_t,
113        count: mach_msg_type_number_t,
114    ) -> kern_return_t;
115}
116
117extern "C" {
118    pub fn thread_policy_get(
119        thread: thread_t,
120        flavor: thread_policy_flavor_t,
121        policy_info: thread_policy_t,
122        count: *mut mach_msg_type_number_t,
123        get_default: *mut boolean_t,
124    ) -> kern_return_t;
125}
126