Skip to content

Commit 3a70a6f

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

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

vm/src/stdlib/os.rs

Lines changed: 28 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,32 @@ mod posix {
23692371
}
23702372
}
23712373

2374+
#[pyfunction]
2375+
fn sched_get_priority_max(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2376+
let max = unsafe { libc::sched_get_priority_max(policy) };
2377+
if max == -1 {
2378+
Err(errno_err(vm))
2379+
} else {
2380+
Ok(max)
2381+
}
2382+
}
2383+
2384+
#[pyfunction]
2385+
fn sched_get_priority_min(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
2386+
let min = unsafe { libc::sched_get_priority_min(policy) };
2387+
if min == -1 {
2388+
Err(errno_err(vm))
2389+
} else {
2390+
Ok(min)
2391+
}
2392+
}
2393+
2394+
#[pyfunction]
2395+
fn sched_yield(vm: &VirtualMachine) -> PyResult<()> {
2396+
let _ = nix::sched::sched_yield().map_err(|e| e.into_pyexception(vm))?;
2397+
Ok(())
2398+
}
2399+
23722400
#[pyfunction]
23732401
fn get_inheritable(fd: RawFd, vm: &VirtualMachine) -> PyResult<bool> {
23742402
use nix::fcntl::fcntl;

0 commit comments

Comments
 (0)