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
#[macro_use]
extern crate cfg_if;
#[macro_use]
extern crate log;
#[cfg(feature = "terminal-logging")]
extern crate simple_logger;

cfg_if! {
    if #[cfg(target_os = "macos")] {
        mod rt_mach;
#[allow(unused, non_camel_case_types, non_snake_case, non_upper_case_globals)]
        mod mach_sys;
        extern crate mach;
        extern crate libc;
        pub use rt_mach::promote_current_thread_to_real_time;
        pub use rt_mach::demote_current_thread_from_real_time;
        pub use rt_mach::RtPriorityHandle;
    } else if #[cfg(target_os = "windows")] {
        extern crate winapi;
        extern crate kernel32;
        mod rt_win;
        pub use rt_win::promote_current_thread_to_real_time;
        pub use rt_win::demote_current_thread_from_real_time;
        pub use rt_win::RtPriorityHandle;
    }
}

#[cfg(test)]
mod tests {
    use promote_current_thread_to_real_time;
    use demote_current_thread_from_real_time;
    use RtPriorityHandle;
    #[cfg(feature = "terminal-logging")]
    use simple_logger;

    #[test]
    fn it_works() {
        #[cfg(feature = "terminal-logging")]
        simple_logger::init().unwrap();
        let rt_prio_handle = RtPriorityHandle::new();
        rt_prio_handle = promote_current_thread_to_real_time(512, 44100).unwrap();
        demote_current_thread_from_real_time(rt_prio_handle).unwrap();
    }
}