mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
fe3ef7d998
This is an easy step toward adopting 2018 edition eventually, and will make any future CL that sets `edition = "2018"` this much smaller. The module system changes in Rust 2018 are described here: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html Generated by running: cargo fix --edition --all in each workspace, followed by bin/fmt. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8 Reviewed-on: https://chromium-review.googlesource.com/1513054 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
38 lines
1.2 KiB
Rust
38 lines
1.2 KiB
Rust
// Copyright 2018 The Chromium OS Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
use crate::{errno_result, Result};
|
|
|
|
/// Enables real time thread priorities in the current thread up to `limit`.
|
|
pub fn set_rt_prio_limit(limit: u64) -> Result<()> {
|
|
let rt_limit_arg = libc::rlimit {
|
|
rlim_cur: limit as libc::rlim_t,
|
|
rlim_max: limit as libc::rlim_t,
|
|
};
|
|
// Safe because the kernel doesn't modify memory that is accessible to the process here.
|
|
let res = unsafe { libc::setrlimit(libc::RLIMIT_RTPRIO, &rt_limit_arg) };
|
|
|
|
if res != 0 {
|
|
errno_result()
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// Sets the current thread to be scheduled using the round robin real time class with `priority`.
|
|
pub fn set_rt_round_robin(priority: i32) -> Result<()> {
|
|
let sched_param = libc::sched_param {
|
|
sched_priority: priority,
|
|
};
|
|
|
|
// Safe because the kernel doesn't modify memory that is accessible to the process here.
|
|
let res =
|
|
unsafe { libc::pthread_setschedparam(libc::pthread_self(), libc::SCHED_RR, &sched_param) };
|
|
|
|
if res != 0 {
|
|
errno_result()
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}
|