added documentation
This commit is contained in:
@@ -22,6 +22,9 @@ fn clock_nanosleep(_clk_id: libc::c_int,
|
|||||||
unsafe { libc::nanosleep(rqtp as *const _, rmtp as *mut _) }
|
unsafe { libc::nanosleep(rqtp as *const _, rmtp as *mut _) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sleeps for the given duration.
|
||||||
|
///
|
||||||
|
/// Uses `clock_nanosleep` on linux and `nanosleep` on darwin.
|
||||||
pub fn sleep(duration: Duration) -> Result<Duration, libc::c_int> {
|
pub fn sleep(duration: Duration) -> Result<Duration, libc::c_int> {
|
||||||
let ts = duration_to_timespec(duration);
|
let ts = duration_to_timespec(duration);
|
||||||
let mut remain = libc::timespec {
|
let mut remain = libc::timespec {
|
||||||
@@ -48,15 +51,31 @@ fn timespec_to_duration(timespec: libc::timespec) -> Duration {
|
|||||||
Duration::new(timespec.tv_sec as u64, timespec.tv_nsec as u32)
|
Duration::new(timespec.tv_sec as u64, timespec.tv_nsec as u32)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set scheduler policy and priority for process with given pid.
|
||||||
|
///
|
||||||
|
/// If `pid` equals zero, the policy of the calling process will be set.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// // set *round-robin* policy (default) and priority 99 (realtime) for own process
|
||||||
|
/// set_scheduler(0, libc::SCHED_RR, 99);
|
||||||
|
/// ```
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn set_scheduler(policy: i32, priority: i32) -> libc::c_int {
|
pub fn set_scheduler(pid: libc::pid_t, policy: libc::c_int, priority: libc::c_int) -> libc::c_int {
|
||||||
let pid: libc::pid_t = 0;
|
|
||||||
let param = libc::sched_param { sched_priority: priority };
|
let param = libc::sched_param { sched_priority: priority };
|
||||||
|
unsafe { libc::sched_setscheduler(pid, policy, ¶m) }
|
||||||
unsafe { libc::sched_setscheduler(pid as libc::pid_t, policy as libc::c_int, ¶m) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set scheduler *round-robin* policy (default) and priority for own process.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// // set *round-robin* policy (default) and priority 99 (realtime)
|
||||||
|
/// set_priority(99);
|
||||||
|
/// ```
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn set_priority(priority: i32) -> libc::c_int {
|
pub fn set_priority(priority: i32) -> libc::c_int {
|
||||||
set_scheduler(libc::SCHED_RR, priority)
|
set_scheduler(0, libc::SCHED_RR, priority)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user