Skip to content

Commit c90cd0f

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

vm/src/stdlib/os.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,8 @@ mod posix {
20862086
const EX_NOPERM: i8 = exitcode::NOPERM as i8;
20872087
#[pyattr]
20882088
const EX_CONFIG: i8 = exitcode::CONFIG as i8;
2089+
#[pyattr]
2090+
use libc::{SCHED_BATCH, SCHED_FIFO, SCHED_IDLE, SCHED_OTHER, SCHED_RR};
20892091

20902092
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
20912093
#[pyattr]
@@ -2369,6 +2371,38 @@ mod posix {
23692371
}
23702372
}
23712373

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

0 commit comments

Comments
 (0)