Merge pull request #3030 from zetwhite/os_sched

posix : implement sched_param class
This commit is contained in:
Jeong YunWon
2021-09-18 20:40:21 +09:00
committed by GitHub

View File

@@ -2048,6 +2048,7 @@ mod posix {
use super::*;
use crate::builtins::list::PyListRef;
use crate::slots::SlotConstructor;
use crate::utils::ToCString;
use bitflags::bitflags;
use nix::unistd::{self, Gid, Pid, Uid};
@@ -2447,6 +2448,51 @@ mod posix {
Ok(())
}
#[pyattr]
#[pyclass(name = "sched_param")]
#[derive(Debug)]
struct SchedParam {
sched_priority: PyObjectRef,
}
impl PyValue for SchedParam {
fn class(_vm: &VirtualMachine) -> &PyTypeRef {
Self::static_type()
}
}
impl TryFromObject for SchedParam {
fn try_from_object(_vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
Ok(SchedParam {
sched_priority: obj,
})
}
}
#[pyimpl(with(SlotConstructor))]
impl SchedParam {
#[pyproperty]
fn sched_priority(&self, vm: &VirtualMachine) -> PyObjectRef {
self.sched_priority.clone().into_pyobject(vm)
}
#[pymethod(magic)]
fn repr(&self, vm: &VirtualMachine) -> PyResult<String> {
let sched_priority_repr = vm.to_repr(&self.sched_priority)?;
Ok(format!(
"posix.sched_param(sched_priority = {})",
sched_priority_repr.as_str()
))
}
}
impl SlotConstructor for SchedParam {
type Args = SchedParam;
fn py_new(cls: PyTypeRef, sched_param: Self::Args, vm: &VirtualMachine) -> PyResult {
sched_param.into_pyresult_with_type(vm, cls)
}
}
#[pyfunction]
fn get_inheritable(fd: RawFd, vm: &VirtualMachine) -> PyResult<bool> {
use nix::fcntl::fcntl;