use std::process::Command;
pub fn low_priority_command(program: &str) -> Command {
super::sys::low_priority_command(program)
}
pub fn lower_current_thread_priority() {
#[cfg(any(target_os = "macos", target_os = "ios"))]
{
const QOS_CLASS_UTILITY: u32 = 0x11;
unsafe extern "C" {
fn pthread_set_qos_class_self_np(qos_class: u32, relative_priority: i32) -> i32;
}
unsafe {
let _ = pthread_set_qos_class_self_np(QOS_CLASS_UTILITY, 0);
}
}
#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))]
{
unsafe extern "C" {
fn nice(inc: i32) -> i32;
}
unsafe {
let _ = nice(10);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn el_programa_pedido_siempre_va_en_la_linea() {
let command = low_priority_command("mi-programa");
let line: Vec<_> = std::iter::once(command.get_program()).chain(command.get_args()).collect();
assert!(line.iter().any(|part| *part == "mi-programa"), "{line:?}");
}
#[test]
fn bajar_la_prioridad_del_hilo_es_seguro() {
std::thread::spawn(lower_current_thread_priority).join().unwrap();
}
}