Skip to content

Commit aad297a

Browse files
committed
Merge pull request rust-lang#79 from polachok/sched
POSIX sched_* APIs
2 parents 94e9b3c + 557c670 commit aad297a

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

libc-test/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ fn main() {
1313
let apple = target.contains("apple");
1414
let musl = target.contains("musl");
1515
let freebsd = target.contains("freebsd");
16+
let mips = target.contains("mips");
1617
let bsdlike = freebsd || apple;
1718
let mut cfg = ctest::TestGenerator::new();
1819

@@ -112,10 +113,12 @@ fn main() {
112113
if !musl {
113114
cfg.header("linux/netlink.h");
114115
}
116+
cfg.header("sched.h");
115117
}
116118

117119
if freebsd {
118120
cfg.header("pthread_np.h");
121+
cfg.header("sched.h");
119122
}
120123

121124
cfg.type_name(move |ty, is_struct| {
@@ -222,6 +225,8 @@ fn main() {
222225
"RLIMIT_NLIMITS" |
223226
"TCP_COOKIE_TRANSACTIONS" |
224227
"RLIMIT_RTTIME" if musl => true,
228+
// work around super old mips toolchain
229+
"SCHED_IDLE" => mips,
225230

226231
_ => false,
227232
}

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ s! {
9999
pub f_fsid: ::c_ulong,
100100
pub f_namemax: ::c_ulong,
101101
}
102+
103+
pub struct sched_param {
104+
pub sched_priority: ::c_int,
105+
}
102106
}
103107

104108
pub const EXIT_FAILURE: ::c_int = 1;
@@ -514,6 +518,10 @@ pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as *mut _;
514518
pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = 0 as *mut _;
515519
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2;
516520

521+
pub const SCHED_FIFO: ::c_int = 1;
522+
pub const SCHED_OTHER: ::c_int = 2;
523+
pub const SCHED_RR: ::c_int = 3;
524+
517525
extern {
518526
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
519527
-> ::c_int;
@@ -536,6 +544,8 @@ extern {
536544
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
537545
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
538546
len: ::off_t) -> ::c_int;
547+
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
548+
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
539549
}
540550

541551
cfg_if! {

src/unix/notbsd/linux/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
281281
pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 1;
282282
pub const __SIZEOF_PTHREAD_COND_T: usize = 48;
283283

284+
pub const SCHED_OTHER: ::c_int = 0;
285+
pub const SCHED_FIFO: ::c_int = 1;
286+
pub const SCHED_RR: ::c_int = 2;
287+
pub const SCHED_BATCH: ::c_int = 3;
288+
pub const SCHED_IDLE: ::c_int = 5;
289+
284290
extern {
285291
pub fn shm_open(name: *const c_char, oflag: ::c_int,
286292
mode: mode_t) -> ::c_int;

src/unix/notbsd/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ s! {
8686
pub tm_gmtoff: ::c_long,
8787
pub tm_zone: *const ::c_char,
8888
}
89+
90+
pub struct sched_param {
91+
pub sched_priority: ::c_int,
92+
#[cfg(target_env = "musl")]
93+
pub sched_ss_low_priority: ::c_int,
94+
#[cfg(target_env = "musl")]
95+
pub sched_ss_repl_period: ::timespec,
96+
#[cfg(target_env = "musl")]
97+
pub sched_ss_init_budget: ::timespec,
98+
#[cfg(target_env = "musl")]
99+
pub sched_ss_max_repl: ::c_int,
100+
}
89101
}
90102

91103
// intentionally not public, only used for fd_set
@@ -377,6 +389,10 @@ extern {
377389
pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void;
378390
pub fn setgroups(ngroups: ::size_t,
379391
ptr: *const ::gid_t) -> ::c_int;
392+
pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int;
393+
pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int;
394+
pub fn sched_get_priority_max(policy: ::c_int) -> ::c_int;
395+
pub fn sched_get_priority_min(policy: ::c_int) -> ::c_int;
380396
}
381397

382398
cfg_if! {

0 commit comments

Comments
 (0)