Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,7 @@ def test_sched_yield(self):
posix.sched_yield()

@requires_sched_h
@unittest.skip("TODO: RUSTPYTHON https://github.com/rust-lang/libc/pull/2384")
@unittest.skipUnless(hasattr(posix, 'sched_get_priority_max'),
"requires sched_get_priority_max()")
def test_sched_priority(self):
Expand Down
61 changes: 61 additions & 0 deletions vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,39 @@ mod posix {
#[pyattr]
const EX_CONFIG: i8 = exitcode::CONFIG as i8;

#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd"
))]
#[pyattr]
const SCHED_RR: i32 = libc::SCHED_RR;
#[cfg(any(
target_os = "linux",
target_os = "android",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd"
))]
#[pyattr]
const SCHED_FIFO: i32 = libc::SCHED_FIFO;
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "netbsd"
))]
#[pyattr]
const SCHED_OTHER: i32 = libc::SCHED_OTHER;
#[cfg(any(target_os = "linux", target_os = "android"))]
#[pyattr]
const SCHED_IDLE: i32 = libc::SCHED_IDLE;
#[cfg(any(target_os = "linux", target_os = "android"))]
#[pyattr]
const SCHED_BATCH: i32 = libc::SCHED_BATCH;

#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
#[pyattr]
const POSIX_SPAWN_OPEN: i32 = PosixSpawnFileActionIdentifier::Open as i32;
Expand Down Expand Up @@ -2369,6 +2402,34 @@ mod posix {
}
}

#[cfg(not(target_os = "redox"))]
#[pyfunction]
fn sched_get_priority_max(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
let max = unsafe { libc::sched_get_priority_max(policy) };
if max == -1 {
Err(errno_err(vm))
} else {
Ok(max)
}
}

#[cfg(not(target_os = "redox"))]
#[pyfunction]
fn sched_get_priority_min(policy: i32, vm: &VirtualMachine) -> PyResult<i32> {
let min = unsafe { libc::sched_get_priority_min(policy) };
if min == -1 {
Err(errno_err(vm))
} else {
Ok(min)
}
}

#[pyfunction]
fn sched_yield(vm: &VirtualMachine) -> PyResult<()> {
let _ = nix::sched::sched_yield().map_err(|e| e.into_pyexception(vm))?;
Ok(())
}

#[pyfunction]
fn get_inheritable(fd: RawFd, vm: &VirtualMachine) -> PyResult<bool> {
use nix::fcntl::fcntl;
Expand Down