// Copyright 2018 The ChromiumOS Authors1// Use of this source code is governed by a BSD-style license that can be2// found in the LICENSE file.34use std::mem::MaybeUninit;56use super::errno_result;7use super::Result;89/// Enables real time thread priorities in the current thread up to `limit`.10pub fn set_rt_prio_limit(limit: u64) -> Result<()> {11let rt_limit_arg = libc::rlimit64 {12rlim_cur: limit,13rlim_max: limit,14};15// SAFETY:16// Safe because the kernel doesn't modify memory that is accessible to the process here.17let res = unsafe { libc::setrlimit64(libc::RLIMIT_RTPRIO, &rt_limit_arg) };1819if res != 0 {20errno_result()21} else {22Ok(())23}24}2526/// Sets the current thread to be scheduled using the round robin real time class with `priority`.27pub fn set_rt_round_robin(priority: i32) -> Result<()> {28// SAFETY:29// Safe because sched_param only contains primitive types for which zero30// initialization is valid.31let mut sched_param: libc::sched_param = unsafe { MaybeUninit::zeroed().assume_init() };32sched_param.sched_priority = priority;3334let res =35// SAFETY:36// Safe because the kernel doesn't modify memory that is accessible to the process here.37unsafe { libc::pthread_setschedparam(libc::pthread_self(), libc::SCHED_RR, &sched_param) };3839if res != 0 {40errno_result()41} else {42Ok(())43}44}454647