From d8bbb424ab819640f48cb6cdc6279de9adb249a7 Mon Sep 17 00:00:00 2001 From: zetwhite Date: Wed, 1 Sep 2021 19:57:37 +0900 Subject: [PATCH 1/2] Add os.sched_yield, os.sched_get_priority_min, os.sched_get_priority_max --- vm/src/stdlib/os.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/vm/src/stdlib/os.rs b/vm/src/stdlib/os.rs index 79c90ebd0c..775abc06b1 100644 --- a/vm/src/stdlib/os.rs +++ b/vm/src/stdlib/os.rs @@ -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; @@ -2369,6 +2402,34 @@ mod posix { } } + #[cfg(not(target_os = "redox"))] + #[pyfunction] + fn sched_get_priority_max(policy: i32, vm: &VirtualMachine) -> PyResult { + 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 { + 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 { use nix::fcntl::fcntl; From 7359f9dda030f73921ab2acf088e51838df1e2ec Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 2 Sep 2021 20:20:11 +0900 Subject: [PATCH 2/2] skip test_sched_priority for now --- Lib/test/test_posix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index e379895c68..7a4d59e181 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -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):