fn set_limits()

in src/rt_linux.rs [155:175]


fn set_limits(request: u64, max: u64) -> Result<(), AudioThreadPriorityError> {
    // Set a soft limit to the limit requested, to be able to handle going over the limit using
    // SIGXCPU. Set the hard limit to the maximum slice to prevent getting SIGKILL.
    #[allow(clippy::useless_conversion)]
    let new_limit = libc::rlimit {
        rlim_cur: request
            .try_into()
            .map_err(|_| AudioThreadPriorityError::new("setrlimit"))?,
        rlim_max: max
            .try_into()
            .map_err(|_| AudioThreadPriorityError::new("setrlimit"))?,
    };
    if unsafe { libc::setrlimit(libc::RLIMIT_RTTIME, &new_limit) } < 0 {
        return Err(AudioThreadPriorityError::new_with_inner(
            "setrlimit",
            Box::new(OSError::last_os_error()),
        ));
    }

    Ok(())
}