Skip to content

Commit 2df379a

Browse files
author
Alexander Polyakov
committed
Fix build for musl
1 parent c2207b7 commit 2df379a

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/resource.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ mod platform {
6666
}
6767
}
6868

69+
#[cfg(target_env="musl")]
70+
pub fn get_priority(which: i32, who: i32) -> Result<i32, ()> {
71+
set_errno(Errno(0));
72+
let priority = unsafe { getpriority(which, who as u32) };
73+
match errno().0 {
74+
0 => Ok(priority),
75+
_ => Err(()),
76+
}
77+
}
78+
79+
#[cfg(target_env="musl")]
80+
pub fn set_priority(which: i32, who: i32, priority: i32) -> Result<(), ()> {
81+
match unsafe { setpriority(which, who as u32, priority) } {
82+
0 => Ok(()),
83+
_ => Err(()),
84+
}
85+
}
86+
6987
// FreeBSD
7088
#[cfg(target_os="freebsd")]
7189
pub fn get_priority(which: i32, who: i32) -> Result<i32, ()> {

src/sched.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn set_self_policy(policy: Policy, priority: i32) -> Result<(), ()> {
3434
/// Set the scheduling policy for a process
3535
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
3636
pub fn set_policy(pid: i32, policy: Policy, priority: i32) -> Result<(), ()> {
37+
use std::mem;
3738
let c_policy = match policy {
3839
Policy::Other => SCHED_OTHER,
3940
Policy::Fifo => SCHED_FIFO,
@@ -42,7 +43,8 @@ pub fn set_policy(pid: i32, policy: Policy, priority: i32) -> Result<(), ()> {
4243
Policy::Idle => SCHED_IDLE,
4344
Policy::Deadline => SCHED_DEADLINE,
4445
};
45-
let params = sched_param { sched_priority: priority };
46+
let mut params: sched_param = unsafe { mem::zeroed() };
47+
params.sched_priority = priority;
4648
let params_ptr: *const sched_param = &params;
4749

4850
match unsafe { sched_setscheduler(pid, c_policy, params_ptr) } {

0 commit comments

Comments
 (0)