1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//! This module corresponds to `mach/thread_policy.h`.

use core::mem::size_of;

use crate::boolean::boolean_t;
use crate::kern_return::kern_return_t;
use crate::mach_types::thread_t;
use crate::message::mach_msg_type_number_t;
use crate::vm_types::{integer_t, natural_t};

pub type thread_policy_t        = *mut integer_t;
pub type thread_policy_flavor_t = natural_t;

pub const THREAD_STANDARD_POLICY:        thread_policy_flavor_t = 1;
pub const THREAD_EXTENDED_POLICY:        thread_policy_flavor_t = 1;
pub const THREAD_TIME_CONSTRAINT_POLICY: thread_policy_flavor_t = 2;
pub const THREAD_PRECEDENCE_POLICY:      thread_policy_flavor_t = 3;
pub const THREAD_AFFINITY_POLICY:        thread_policy_flavor_t = 4;
pub const THREAD_BACKGROUND_POLICY:      thread_policy_flavor_t = 5;
pub const THREAD_LATENCY_QOS_POLICY:     thread_policy_flavor_t = 7;
pub const THREAD_THROUGHPUT_QOS_POLICY:  thread_policy_flavor_t = 8;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_standard_policy_t {
    pub no_data: natural_t,
}
pub type thread_standard_policy        = thread_standard_policy_t;
pub type thread_standard_policy_data_t = thread_standard_policy_t;
pub const THREAD_STANDARD_POLICY_COUNT: mach_msg_type_number_t = 0;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_extended_policy_t {
    pub timeshare: boolean_t,
}
pub type thread_extended_policy        = thread_extended_policy_t;
pub type thread_extended_policy_data_t = thread_extended_policy_t;
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_extended_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_time_constraint_policy_t {
    pub period:      u32,
    pub computation: u32,
    pub constraint:  u32,
    pub preemptible: boolean_t,
}
pub type thread_time_constraint_policy        = thread_time_constraint_policy_t;
pub type thread_time_constraint_policy_data_t = thread_time_constraint_policy_t;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_time_constraint_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_precedence_policy_t {
    pub importance: integer_t,
}
pub type thread_precedence_policy        = thread_precedence_policy_t;
pub type thread_precedence_policy_data_t = thread_precedence_policy_t;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_precedence_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_affinity_policy_t {
    pub affinity_tag: integer_t,
}
pub const THREAD_AFFINITY_TAG_NULL: integer_t = 0;
pub type thread_affinity_policy        = thread_affinity_policy_t;
pub type thread_affinity_policy_data_t = thread_affinity_policy_t;
pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_affinity_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_background_policy_t {
    pub priority: integer_t,
}
pub type thread_background_policy        = thread_background_policy_t;
pub type thread_background_policy_data_t = thread_background_policy_t;
pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_background_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_latency_qos_policy_t {
    pub thread_latency_qos_tier: thread_latency_qos_t,
}
pub type thread_latency_qos_t = integer_t;
pub type thread_latency_qos_policy        = thread_latency_qos_policy_t;
pub type thread_latency_qos_policy_data_t = thread_latency_qos_policy_t;
pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_latency_qos_policy_t>() / size_of::<integer_t>() ) as _;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_throughput_qos_policy_t {
    pub thread_throughput_qos_tier: thread_throughput_qos_t,
}
pub type thread_throughput_qos_t = integer_t;
pub type thread_throughput_qos_policy         = thread_throughput_qos_policy_t;
pub type thread_throughput_qos_policy_data_t  = thread_throughput_qos_policy_t;
pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
    ( size_of::<thread_throughput_qos_policy_t>() / size_of::<integer_t>() ) as _;

extern "C" {
    pub fn thread_policy_set(
        thread: thread_t,
        flavor: thread_policy_flavor_t,
        policy_info: thread_policy_t,
        count: mach_msg_type_number_t,
    ) -> kern_return_t;
}

extern "C" {
    pub fn thread_policy_get(
        thread: thread_t,
        flavor: thread_policy_flavor_t,
        policy_info: thread_policy_t,
        count: *mut mach_msg_type_number_t,
        get_default: *mut boolean_t,
    ) -> kern_return_t;
}