Skip to content

Commit

Permalink
Merge pull request rust-lang#79 from polachok/sched
Browse files Browse the repository at this point in the history
POSIX sched_* APIs
  • Loading branch information
alexcrichton committed Nov 30, 2015
2 parents 94e9b3c + 557c670 commit aad297a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn main() {
let apple = target.contains("apple");
let musl = target.contains("musl");
let freebsd = target.contains("freebsd");
let mips = target.contains("mips");
let bsdlike = freebsd || apple;
let mut cfg = ctest::TestGenerator::new();

Expand Down Expand Up @@ -112,10 +113,12 @@ fn main() {
if !musl {
cfg.header("linux/netlink.h");
}
cfg.header("sched.h");
}

if freebsd {
cfg.header("pthread_np.h");
cfg.header("sched.h");
}

cfg.type_name(move |ty, is_struct| {
Expand Down Expand Up @@ -222,6 +225,8 @@ fn main() {
"RLIMIT_NLIMITS" |
"TCP_COOKIE_TRANSACTIONS" |
"RLIMIT_RTTIME" if musl => true,
// work around super old mips toolchain
"SCHED_IDLE" => mips,

_ => false,
}
Expand Down
10 changes: 10 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ s! {
pub f_fsid: ::c_ulong,
pub f_namemax: ::c_ulong,
}

pub struct sched_param {
pub sched_priority: ::c_int,
}
}

pub const EXIT_FAILURE: ::c_int = 1;
Expand Down Expand Up @@ -514,6 +518,10 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;

pub const SCHED_FIFO: ::c_int = 1;
pub const SCHED_OTHER: ::c_int = 2;
pub const SCHED_RR: ::c_int = 3;

extern {
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
Expand All @@ -536,6 +544,8 @@ extern {
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
len: ::off_t) -> ::c_int;
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
}

cfg_if! {
Expand Down
6 changes: 6 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;

pub const SCHED_OTHER: ::c_int = 0;
pub const SCHED_FIFO: ::c_int = 1;
pub const SCHED_RR: ::c_int = 2;
pub const SCHED_BATCH: ::c_int = 3;
pub const SCHED_IDLE: ::c_int = 5;

extern {
pub fn shm_open(name: *const c_char, oflag: ::c_int,
mode: mode_t) -> ::c_int;
Expand Down
16 changes: 16 additions & 0 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ s! {
pub tm_gmtoff: ::c_long,
pub tm_zone: *const ::c_char,
}

pub struct sched_param {
pub sched_priority: ::c_int,
#[cfg(target_env = "musl")]
pub sched_ss_low_priority: ::c_int,
#[cfg(target_env = "musl")]
pub sched_ss_repl_period: ::timespec,
#[cfg(target_env = "musl")]
pub sched_ss_init_budget: ::timespec,
#[cfg(target_env = "musl")]
pub sched_ss_max_repl: ::c_int,
}
}

// intentionally not public, only used for fd_set
Expand Down Expand Up @@ -377,6 +389,10 @@ extern {
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
pub fn setgroups(ngroups: ::size_t,
ptr: *const ::gid_t) -> ::c_int;
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down

0 comments on commit aad297a

Please sign in to comment.