python-plugin: RAII (PyOwned/PyBorrowed) + autodecode enum; crate: ny-llvmc --emit exe with NyRT link; tools: build_llvm.sh crate-exe path + crate_exe_smoke; CURRENT_TASK update
This commit is contained in:
19
plugins/nyash-python-plugin/src/gil.rs
Normal file
19
plugins/nyash-python-plugin/src/gil.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use crate::ffi::{CPython, PyGILState_STATE};
|
||||
|
||||
pub struct GILGuard<'a> {
|
||||
cpy: &'a CPython,
|
||||
state: PyGILState_STATE,
|
||||
}
|
||||
|
||||
impl<'a> GILGuard<'a> {
|
||||
pub fn acquire(cpy: &'a CPython) -> Self {
|
||||
let state = unsafe { (cpy.PyGILState_Ensure)() };
|
||||
GILGuard { cpy, state }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Drop for GILGuard<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe { (self.cpy.PyGILState_Release)(self.state) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user