|
1 | | -use crate::mach_sys::*; |
2 | 1 | use crate::AudioThreadPriorityError; |
3 | | -use libc::{pthread_self, pthread_t}; |
| 2 | +use libc::{pthread_mach_thread_np, pthread_self, thread_policy_t}; |
4 | 3 | use log::info; |
| 4 | +use mach2::boolean::boolean_t; |
5 | 5 | use mach2::kern_return::{kern_return_t, KERN_SUCCESS}; |
6 | 6 | use mach2::mach_time::{mach_timebase_info, mach_timebase_info_data_t}; |
7 | 7 | use mach2::message::mach_msg_type_number_t; |
8 | 8 | use mach2::port::mach_port_t; |
9 | | -use std::mem::size_of; |
10 | | - |
11 | | -extern "C" { |
12 | | - fn pthread_mach_thread_np(tid: pthread_t) -> mach_port_t; |
13 | | - // Those functions are commented out in thread_policy.h but somehow it works just fine !? |
14 | | - fn thread_policy_set( |
15 | | - thread: thread_t, |
16 | | - flavor: thread_policy_flavor_t, |
17 | | - policy_info: thread_policy_t, |
18 | | - count: mach_msg_type_number_t, |
19 | | - ) -> kern_return_t; |
20 | | - fn thread_policy_get( |
21 | | - thread: thread_t, |
22 | | - flavor: thread_policy_flavor_t, |
23 | | - policy_info: thread_policy_t, |
24 | | - count: &mut mach_msg_type_number_t, |
25 | | - get_default: &mut boolean_t, |
26 | | - ) -> kern_return_t; |
27 | | -} |
28 | | - |
29 | | -// can't use size_of in const fn just now in stable, use a macro for now. |
30 | | -macro_rules! THREAD_TIME_CONSTRAINT_POLICY_COUNT { |
31 | | - () => { |
32 | | - (size_of::<thread_time_constraint_policy_data_t>() / size_of::<integer_t>()) as u32 |
33 | | - }; |
34 | | -} |
| 9 | +use mach2::thread_policy::{ |
| 10 | + thread_policy_get, thread_policy_set, thread_time_constraint_policy_data_t, |
| 11 | + THREAD_TIME_CONSTRAINT_POLICY, THREAD_TIME_CONSTRAINT_POLICY_COUNT, |
| 12 | +}; |
35 | 13 |
|
36 | 14 | #[derive(Debug)] |
37 | 15 | pub struct RtPriorityHandleInternal { |
@@ -68,7 +46,7 @@ pub fn demote_current_thread_from_real_time_internal( |
68 | 46 | h.tid, |
69 | 47 | THREAD_TIME_CONSTRAINT_POLICY, |
70 | 48 | (&mut h.previous_time_constraint_policy) as *mut _ as thread_policy_t, |
71 | | - THREAD_TIME_CONSTRAINT_POLICY_COUNT!(), |
| 49 | + THREAD_TIME_CONSTRAINT_POLICY_COUNT, |
72 | 50 | ); |
73 | 51 | if rv != KERN_SUCCESS { |
74 | 52 | return Err(AudioThreadPriorityError::new( |
@@ -110,7 +88,7 @@ pub fn promote_current_thread_to_real_time_internal( |
110 | 88 | // returning, it means there are no current settings because of other factor, and the |
111 | 89 | // default was returned instead. |
112 | 90 | let mut get_default: boolean_t = 0; |
113 | | - let mut count: mach_msg_type_number_t = THREAD_TIME_CONSTRAINT_POLICY_COUNT!(); |
| 91 | + let mut count: mach_msg_type_number_t = THREAD_TIME_CONSTRAINT_POLICY_COUNT; |
114 | 92 | let mut rv: kern_return_t = thread_policy_get( |
115 | 93 | tid, |
116 | 94 | THREAD_TIME_CONSTRAINT_POLICY, |
@@ -160,7 +138,7 @@ pub fn promote_current_thread_to_real_time_internal( |
160 | 138 | tid, |
161 | 139 | THREAD_TIME_CONSTRAINT_POLICY, |
162 | 140 | (&mut time_constraints) as *mut _ as thread_policy_t, |
163 | | - THREAD_TIME_CONSTRAINT_POLICY_COUNT!(), |
| 141 | + THREAD_TIME_CONSTRAINT_POLICY_COUNT, |
164 | 142 | ); |
165 | 143 | if rv != KERN_SUCCESS { |
166 | 144 | return Err(AudioThreadPriorityError::new( |
|
0 commit comments