summaryrefslogtreecommitdiffstats
path: root/third_party/rust/mach2/src/thread_policy.rs
blob: aa17e6ea31413cc5cc03a83c1a08bef1e0ad9ee4 (plain)
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
//! This module corresponds to `mach/thread_policy.h`.

use boolean::boolean_t;
use kern_return::kern_return_t;
use libc::thread_policy_t;
use mach_types::thread_t;
use message::mach_msg_type_number_t;
use vm_types::{integer_t, natural_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 {
    pub no_data: natural_t,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_extended_policy {
    pub timeshare: boolean_t,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_time_constraint_policy {
    pub period: u32,
    pub computation: u32,
    pub constraint: u32,
    pub preemptible: boolean_t,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_precedence_policy {
    pub importance: integer_t,
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_affinity_policy {
    pub affinity_tag: integer_t,
}

pub const THREAD_AFFINITY_TAG_NULL: integer_t = 0;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_background_policy {
    pub priority: integer_t,
}

pub type thread_latency_qos_t = integer_t;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_latency_qos_policy {
    thread_latency_qos_tier: thread_latency_qos_t,
}

pub type thread_throughput_qos_t = integer_t;

#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct thread_throughput_qos_policy {
    thread_throughput_qos_tier: thread_throughput_qos_t,
}

pub type thread_standard_policy_data_t = thread_standard_policy;
pub type thread_extended_policy_data_t = thread_extended_policy;
pub type thread_time_constraint_policy_data_t = thread_time_constraint_policy;
pub type thread_precedence_policy_data_t = thread_precedence_policy;
pub type thread_affinity_policy_data_t = thread_affinity_policy;
pub type thread_background_policy_data_t = thread_background_policy;
pub type thread_latency_qos_policy_data_t = thread_latency_qos_policy;
pub type thread_throughput_qos_policy_data_t = thread_throughput_qos_policy;

pub const THREAD_STANDARD_POLICY_COUNT: mach_msg_type_number_t = 0;
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_extended_policy>() / core::mem::size_of::<integer_t>()) as _;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_time_constraint_policy>() / core::mem::size_of::<integer_t>())
        as _;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_precedence_policy>() / core::mem::size_of::<integer_t>()) as _;
pub const THREAD_AFFINITY_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_affinity_policy>() / core::mem::size_of::<integer_t>()) as _;
pub const THREAD_BACKGROUND_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_background_policy>() / core::mem::size_of::<integer_t>()) as _;
pub const THREAD_LATENCY_QOS_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_latency_qos_policy>() / core::mem::size_of::<integer_t>()) as _;
pub const THREAD_THROUGHPUT_QOS_POLICY_COUNT: mach_msg_type_number_t =
    (core::mem::size_of::<thread_throughput_qos_policy>() / core::mem::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;
}