Skip to content

Commit d8bbb42

Browse files
committed
Add os.sched_yield, os.sched_get_priority_min, os.sched_get_priority_max
1 parent 8473ea9 commit d8bbb42

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

vm/src/stdlib/os.rs

+61
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,39 @@ mod posix {
20872087
#[pyattr]
20882088
const EX_CONFIG: i8 = exitcode::CONFIG as i8;
20892089

2090+
#[cfg(any(
2091+
target_os = "linux",
2092+
target_os = "android",
2093+
target_os = "freebsd",
2094+
target_os = "dragonfly",
2095+
target_os = "netbsd"
2096+
))]
2097+
#[pyattr]
2098+
const SCHED_RR: i32 = libc::SCHED_RR;
2099+
#[cfg(any(
2100+
target_os = "linux",
2101+
target_os = "android",
2102+
target_os = "freebsd",
2103+
target_os = "dragonfly",
2104+
target_os = "netbsd"
2105+
))]
2106+
#[pyattr]
2107+
const SCHED_FIFO: i32 = libc::SCHED_FIFO;
2108+
#[cfg(any(
2109+
target_os = "linux",
2110+
target_os = "freebsd",
2111+
target_os = "dragonfly",
2112+
target_os = "netbsd"
2113+
))]
2114+
#[pyattr]
2115+
const SCHED_OTHER: i32 = libc::SCHED_OTHER;
2116+
#[cfg(any(target_os = "linux", target_os = "android"))]
2117+
#[pyattr]
2118+
const SCHED_IDLE: i32 = libc::SCHED_IDLE;
2119+
#[cfg(any(target_os = "linux", target_os = "android"))]
2120+
#[pyattr]
2121+
const SCHED_BATCH: i32 = libc::SCHED_BATCH;
2122+
20902123
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
20912124
#[pyattr]
20922125
const POSIX_SPAWN_OPEN: i32 = PosixSpawnFileActionIdentifier::Open as i32;
@@ -2369,6 +2402,34 @@ mod posix {
23692402
}
23702403
}
23712404

2405+
#[cfg(not(target_os = "redox"))]
2406+
#[pyfunction]
2407+
fn sched_get_priority_max(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2408+
let max = unsafe { libc::sched_get_priority_max(policy) };
2409+
if max == -1 {
2410+
Err(errno_err(vm))
2411+
} else {
2412+
Ok(max)
2413+
}
2414+
}
2415+
2416+
#[cfg(not(target_os = "redox"))]
2417+
#[pyfunction]
2418+
fn sched_get_priority_min(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2419+
let min = unsafe { libc::sched_get_priority_min(policy) };
2420+
if min == -1 {
2421+
Err(errno_err(vm))
2422+
} else {
2423+
Ok(min)
2424+
}
2425+
}
2426+
2427+
#[pyfunction]
2428+
fn sched_yield(vm: &VirtualMachine) -> PyResult<()> {
2429+
let _ = nix::sched::sched_yield().map_err(|e| e.into_pyexception(vm))?;
2430+
Ok(())
2431+
}
2432+
23722433
#[pyfunction]
23732434
fn get_inheritable(fd: RawFd, vm: &VirtualMachine) -> PyResult<bool> {
23742435
use nix::fcntl::fcntl;

0 commit comments

Comments
 (0)