From bb066d5ba8acb599e9ae434eb4020ce6d54afb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=B6rner?= Date: Mon, 3 Apr 2017 19:06:14 +0200 Subject: [PATCH] added documentation --- V2/sleep/src/lib.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/V2/sleep/src/lib.rs b/V2/sleep/src/lib.rs index 119f469..8d0c260 100644 --- a/V2/sleep/src/lib.rs +++ b/V2/sleep/src/lib.rs @@ -22,6 +22,9 @@ fn clock_nanosleep(_clk_id: libc::c_int, 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 { let ts = duration_to_timespec(duration); 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) } +/// 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")] -pub fn set_scheduler(policy: i32, priority: i32) -> libc::c_int { - let pid: libc::pid_t = 0; +pub fn set_scheduler(pid: libc::pid_t, policy: libc::c_int, priority: libc::c_int) -> libc::c_int { let param = libc::sched_param { sched_priority: priority }; - - unsafe { libc::sched_setscheduler(pid as libc::pid_t, policy as libc::c_int, ¶m) } + unsafe { libc::sched_setscheduler(pid, policy, ¶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")] pub fn set_priority(priority: i32) -> libc::c_int { - set_scheduler(libc::SCHED_RR, priority) + set_scheduler(0, libc::SCHED_RR, priority) }