pub fn raise() -> bool {
platform::raise()
}
#[cfg(target_os = "linux")]
#[allow(unsafe_code)]
mod platform {
use std::process::{Command, Stdio};
const PRIORITY: u32 = 15;
const MOST_TIME: u64 = 200_000;
pub fn raise() -> bool {
let limit = libc::rlimit {
rlim_cur: MOST_TIME,
rlim_max: MOST_TIME,
};
if unsafe { libc::setrlimit(libc::RLIMIT_RTTIME, &raw const limit) } < 0 {
return false;
}
let thread = unsafe { libc::gettid() };
Command::new("busctl")
.args([
"call",
"--system",
"org.freedesktop.RealtimeKit1",
"/org/freedesktop/RealtimeKit1",
"org.freedesktop.RealtimeKit1",
"MakeThreadRealtimeWithPID",
"ttu",
])
.arg(std::process::id().to_string())
.arg(thread.to_string())
.arg(PRIORITY.to_string())
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.is_ok_and(|status| status.success())
}
}
#[cfg(not(target_os = "linux"))]
mod platform {
pub fn raise() -> bool {
false
}
}