Skip to content

Commit

Permalink
fix(std/node): use common priority type
Browse files Browse the repository at this point in the history
  • Loading branch information
ecyrbe committed Mar 1, 2020
1 parent bac6159 commit 3125532
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cli/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ use winapi::um::winbase::{
};
#[cfg(windows)]
use winapi::um::winnt::PROCESS_QUERY_LIMITED_INFORMATION;
#[cfg(target_os = "macos")]
#[allow(non_camel_case_types)]
type priority_t = i32;
#[cfg(target_os = "linux")]
#[allow(non_camel_case_types)]
type priority_t = u32;


pub const PRIORITY_LOW: i32 = 19;
pub const PRIORITY_BELOW_NORMAL: i32 = 10;
Expand All @@ -35,7 +42,7 @@ pub const PRIORITY_HIGHEST: i32 = -20;
pub fn get_priority(pid: u32) -> Result<i32, OpError> {
unsafe {
set_errno(Errno(0));
match (libc::getpriority(PRIO_PROCESS as u32, pid as id_t), errno()) {
match (libc::getpriority(PRIO_PROCESS as priority_t, pid as id_t), errno()) {
(-1, Errno(0)) => Ok(PRIORITY_HIGH),
(-1, _) => Err(OpError::from(std::io::Error::last_os_error())),
(priority, _) => Ok(priority),
Expand All @@ -46,7 +53,7 @@ pub fn get_priority(pid: u32) -> Result<i32, OpError> {
#[cfg(unix)]
pub fn set_priority(pid: u32,priority: i32) -> Result<(), OpError> {
unsafe {
match libc::setpriority(PRIO_PROCESS as u32, pid as id_t, priority) {
match libc::setpriority(PRIO_PROCESS as priority_t, pid as id_t, priority) {
-1 => Err(OpError::from(std::io::Error::last_os_error())),
_ => Ok(()),
}
Expand Down

0 comments on commit 3125532

Please sign in to comment.