relibc/header/sched/mod.rs
1//! `sched.h` implementation.
2//!
3//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sched.h.html>.
4
5use crate::{
6 error::ResultExt,
7 header::time::timespec,
8 platform::{
9 Pal, Sys,
10 types::{c_int, pid_t},
11 },
12};
13
14// TODO: There are extensions, but adding more member is breaking ABI for pthread_attr_t
15/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sched.h.html>.
16///
17/// Scheduling parameters required for each supported scheduling policy.
18#[allow(non_camel_case_types)]
19#[repr(C)]
20#[derive(Clone, Copy, Debug)]
21pub struct sched_param {
22 /// Process or thread execution scheduling priority.
23 pub sched_priority: c_int,
24}
25
26/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sched.h.html>.
27///
28/// First in first out (FIFO) scheduling policy.
29pub const SCHED_FIFO: c_int = 0;
30/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sched.h.html>.
31///
32/// Round robin scheduling policy.
33pub const SCHED_RR: c_int = 1;
34/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sched.h.html>.
35///
36/// Another scheduling policy.
37pub const SCHED_OTHER: c_int = 2;
38
39/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_get_priority_max.html>.
40// #[unsafe(no_mangle)]
41pub extern "C" fn sched_get_priority_max(policy: c_int) -> c_int {
42 todo!()
43}
44
45/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_get_priority_max.html>.
46// #[unsafe(no_mangle)]
47pub extern "C" fn sched_get_priority_min(policy: c_int) -> c_int {
48 todo!()
49}
50
51/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_getparam.html>.
52// #[unsafe(no_mangle)]
53pub unsafe extern "C" fn sched_getparam(pid: pid_t, param: *mut sched_param) -> c_int {
54 todo!()
55}
56
57/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_rr_get_interval.html>.
58// #[unsafe(no_mangle)]
59pub extern "C" fn sched_rr_get_interval(pid: pid_t, time: *const timespec) -> c_int {
60 todo!()
61}
62
63/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_setparam.html>.
64// #[unsafe(no_mangle)]
65pub unsafe extern "C" fn sched_setparam(pid: pid_t, param: *const sched_param) -> c_int {
66 todo!()
67}
68
69/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_setscheduler.html>.
70// #[unsafe(no_mangle)]
71pub extern "C" fn sched_setscheduler(
72 pid: pid_t,
73 policy: c_int,
74 param: *const sched_param,
75) -> c_int {
76 todo!()
77}
78
79/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sched_yield.html>.
80///
81/// Force the running thread to relinquish the processor until it again
82/// becomes the head of its thread list.
83#[unsafe(no_mangle)]
84pub extern "C" fn sched_yield() -> c_int {
85 Sys::sched_yield().map(|()| 0).or_minus_one_errno()
86}