forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread.rs
More file actions
58 lines (49 loc) · 1.68 KB
/
thread.rs
File metadata and controls
58 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/// Implementation of the _thread module, currently noop implementation as RustPython doesn't yet
/// support threading
use super::super::pyobject::PyObjectRef;
use crate::function::PyFuncArgs;
use crate::pyobject::PyResult;
use crate::vm::VirtualMachine;
fn rlock_acquire(vm: &VirtualMachine, _args: PyFuncArgs) -> PyResult {
Ok(vm.get_none())
}
fn rlock_release(_zelf: PyObjectRef, _vm: &VirtualMachine) {}
fn rlock_enter(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(vm, args, required = [(instance, None)]);
Ok(instance.clone())
}
fn rlock_exit(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
arg_check!(
vm,
args,
// The context manager protocol requires these, but we don't use them
required = [
(_instance, None),
(_exception_type, None),
(_exception_value, None),
(_traceback, None)
]
);
Ok(vm.get_none())
}
fn get_ident(_vm: &VirtualMachine) -> u32 {
1
}
fn allocate_lock(vm: &VirtualMachine) -> PyResult {
let lock_class = vm.class("_thread", "RLock");
vm.invoke(lock_class.into_object(), vec![])
}
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
let rlock_type = py_class!(ctx, "_thread.RLock", ctx.object(), {
"acquire" => ctx.new_rustfunc(rlock_acquire),
"release" => ctx.new_rustfunc(rlock_release),
"__enter__" => ctx.new_rustfunc(rlock_enter),
"__exit__" => ctx.new_rustfunc(rlock_exit),
});
py_module!(vm, "_thread", {
"RLock" => rlock_type,
"get_ident" => ctx.new_rustfunc(get_ident),
"allocate_lock" => ctx.new_rustfunc(allocate_lock),
})
}