added realtime parameter
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
extern crate libc;
|
||||
|
||||
use std::time::Duration;
|
||||
use libc::{c_int, c_long, time_t, timespec};
|
||||
|
||||
const CLOCK_MONOTONIC: i32 = 1;
|
||||
|
||||
@@ -15,9 +14,9 @@ fn clock_nanosleep(_clk_id: libc::c_int, _flags: libc::c_int, rqtp: *const libc:
|
||||
unsafe { libc::nanosleep(rqtp as *const _, rmtp as *mut _) }
|
||||
}
|
||||
|
||||
pub fn sleep(duration: Duration) -> Result<Duration, c_int> {
|
||||
pub fn sleep(duration: Duration) -> Result<Duration, libc::c_int> {
|
||||
let ts = duration_to_timespec(duration);
|
||||
let mut remain = timespec {
|
||||
let mut remain = libc::timespec {
|
||||
tv_sec: 0,
|
||||
tv_nsec: 0,
|
||||
};
|
||||
@@ -30,13 +29,28 @@ pub fn sleep(duration: Duration) -> Result<Duration, c_int> {
|
||||
}
|
||||
}
|
||||
|
||||
fn duration_to_timespec(duration: Duration) -> timespec {
|
||||
timespec {
|
||||
tv_sec: duration.as_secs() as time_t,
|
||||
tv_nsec: duration.subsec_nanos() as c_long,
|
||||
fn duration_to_timespec(duration: Duration) -> libc::timespec {
|
||||
libc::timespec {
|
||||
tv_sec: duration.as_secs() as libc::time_t,
|
||||
tv_nsec: duration.subsec_nanos() as libc::c_long,
|
||||
}
|
||||
}
|
||||
|
||||
fn timespec_to_duration(timespec: timespec) -> Duration {
|
||||
fn timespec_to_duration(timespec: libc::timespec) -> Duration {
|
||||
Duration::new(timespec.tv_sec as u64, timespec.tv_nsec as u32)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn set_scheduler(policy: i32, priority: i32) -> libc::c_int {
|
||||
let pid: libc::pid_t = 0;
|
||||
let param = libc::sched_param {
|
||||
sched_priority: priority
|
||||
};
|
||||
|
||||
unsafe { libc::sched_setscheduler(pid as libc::pid_t, policy as libc::c_int, ¶m) }
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn set_priority(priority: i32) -> libc::c_int {
|
||||
set_scheduler(libc::SCHED_RR, priority)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user