Skip to content

Commit 4f05959

Browse files
kinetiknzpadenot
authored andcommitted
macOS: Remove mach_sys.rs and use definitions from mach2/libc.
1 parent 14e0b09 commit 4f05959

File tree

3 files changed

+9
-69
lines changed

3 files changed

+9
-69
lines changed

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ impl Error for AudioThreadPriorityError {
8787
cfg_if! {
8888
if #[cfg(target_os = "macos")] {
8989
mod rt_mach;
90-
#[allow(unused, non_camel_case_types, non_snake_case, non_upper_case_globals)]
91-
mod mach_sys;
9290
extern crate mach2;
9391
extern crate libc;
9492
use rt_mach::promote_current_thread_to_real_time_internal;

src/mach_sys.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/rt_mach.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
1-
use crate::mach_sys::*;
21
use crate::AudioThreadPriorityError;
3-
use libc::{pthread_self, pthread_t};
2+
use libc::{pthread_mach_thread_np, pthread_self, thread_policy_t};
43
use log::info;
4+
use mach2::boolean::boolean_t;
55
use mach2::kern_return::{kern_return_t, KERN_SUCCESS};
66
use mach2::mach_time::{mach_timebase_info, mach_timebase_info_data_t};
77
use mach2::message::mach_msg_type_number_t;
88
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+
};
3513

3614
#[derive(Debug)]
3715
pub struct RtPriorityHandleInternal {
@@ -68,7 +46,7 @@ pub fn demote_current_thread_from_real_time_internal(
6846
h.tid,
6947
THREAD_TIME_CONSTRAINT_POLICY,
7048
(&mut h.previous_time_constraint_policy) as *mut _ as thread_policy_t,
71-
THREAD_TIME_CONSTRAINT_POLICY_COUNT!(),
49+
THREAD_TIME_CONSTRAINT_POLICY_COUNT,
7250
);
7351
if rv != KERN_SUCCESS {
7452
return Err(AudioThreadPriorityError::new(
@@ -110,7 +88,7 @@ pub fn promote_current_thread_to_real_time_internal(
11088
// returning, it means there are no current settings because of other factor, and the
11189
// default was returned instead.
11290
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;
11492
let mut rv: kern_return_t = thread_policy_get(
11593
tid,
11694
THREAD_TIME_CONSTRAINT_POLICY,
@@ -160,7 +138,7 @@ pub fn promote_current_thread_to_real_time_internal(
160138
tid,
161139
THREAD_TIME_CONSTRAINT_POLICY,
162140
(&mut time_constraints) as *mut _ as thread_policy_t,
163-
THREAD_TIME_CONSTRAINT_POLICY_COUNT!(),
141+
THREAD_TIME_CONSTRAINT_POLICY_COUNT,
164142
);
165143
if rv != KERN_SUCCESS {
166144
return Err(AudioThreadPriorityError::new(

0 commit comments

Comments
 (0)