1 // Copyright 2018 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use crate::{errno_result, Result}; 6 7 /// Enables real time thread priorities in the current thread up to `limit`. set_rt_prio_limit(limit: u64) -> Result<()>8pub fn set_rt_prio_limit(limit: u64) -> Result<()> { 9 let rt_limit_arg = libc::rlimit { 10 rlim_cur: limit as libc::rlim_t, 11 rlim_max: limit as libc::rlim_t, 12 }; 13 // Safe because the kernel doesn't modify memory that is accessible to the process here. 14 let res = unsafe { libc::setrlimit(libc::RLIMIT_RTPRIO, &rt_limit_arg) }; 15 16 if res != 0 { 17 errno_result() 18 } else { 19 Ok(()) 20 } 21 } 22 23 /// Sets the current thread to be scheduled using the round robin real time class with `priority`. set_rt_round_robin(priority: i32) -> Result<()>24pub fn set_rt_round_robin(priority: i32) -> Result<()> { 25 let sched_param = libc::sched_param { 26 sched_priority: priority, 27 }; 28 29 // Safe because the kernel doesn't modify memory that is accessible to the process here. 30 let res = 31 unsafe { libc::pthread_setschedparam(libc::pthread_self(), libc::SCHED_RR, &sched_param) }; 32 33 if res != 0 { 34 errno_result() 35 } else { 36 Ok(()) 37 } 38 } 39