Skip to content

Commit a0624dd

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

vm/src/stdlib/os.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,9 @@ mod posix {
20862086
const EX_NOPERM: i8 = exitcode::NOPERM as i8;
20872087
#[pyattr]
20882088
const EX_CONFIG: i8 = exitcode::CONFIG as i8;
2089+
#[cfg(target_os = "linux")]
2090+
#[pyattr]
2091+
use libc::{SCHED_BATCH, SCHED_FIFO, SCHED_IDLE, SCHED_OTHER, SCHED_RR};
20892092

20902093
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
20912094
#[pyattr]
@@ -2369,6 +2372,38 @@ mod posix {
23692372
}
23702373
}
23712374

2375+
#[cfg(target_os = "linux")]
2376+
#[pyfunction]
2377+
fn sched_get_priority_max(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2378+
let max = unsafe { libc::sched_get_priority_max(policy) };
2379+
if max == -1 {
2380+
Err(errno_err(vm))
2381+
} else {
2382+
Ok(max)
2383+
}
2384+
}
2385+
2386+
#[cfg(target_os = "linux")]
2387+
#[pyfunction]
2388+
fn sched_get_priority_min(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2389+
let min = unsafe { libc::sched_get_priority_min(policy) };
2390+
if min == -1 {
2391+
Err(errno_err(vm))
2392+
} else {
2393+
Ok(min)
2394+
}
2395+
}
2396+
2397+
#[cfg(target_os = "linux")]
2398+
#[pyfunction]
2399+
fn sched_yield(vm: &VirtualMachine) -> PyResult<()> {
2400+
let res = nix::sched::sched_yield();
2401+
match res {
2402+
Ok(_) => Ok(()),
2403+
Err(err) => Err(err.into_pyexception(vm)),
2404+
}
2405+
}
2406+
23722407
#[pyfunction]
23732408
fn get_inheritable(fd: RawFd, vm: &VirtualMachine) -> PyResult<bool> {
23742409
use nix::fcntl::fcntl;

0 commit comments

Comments
 (0)