Enable `GILProtected` access via `PyVisit`
Closes #3615 This simply adds a new method which uses the existence of a `PyVisit` object as proof that the GIL is held instead of a `Python` object. This allows `GILProtected` to be used in instances where contained Python objects need to participate in garbage collection. Usage in this situation should be valid since no Python calls are made and this does not provide any additional mechanism for accessing a `Python` object.
This commit is contained in:
parent
81ad2e8bab
commit
3249feb85c
|
@ -0,0 +1 @@
|
|||
Add `traverse` method to `GILProtected`
|
|
@ -1,5 +1,5 @@
|
|||
//! Synchronization mechanisms based on the Python GIL.
|
||||
use crate::{types::PyString, types::PyType, Py, PyErr, Python};
|
||||
use crate::{types::PyString, types::PyType, Py, PyErr, PyVisit, Python};
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
/// Value with concurrent access protected by the GIL.
|
||||
|
@ -37,6 +37,11 @@ impl<T> GILProtected<T> {
|
|||
pub fn get<'py>(&'py self, _py: Python<'py>) -> &'py T {
|
||||
&self.value
|
||||
}
|
||||
|
||||
/// Gain access to the inner value by giving proof that garbage collection is happening.
|
||||
pub fn traverse<'py>(&'py self, _visit: PyVisit<'py>) -> &'py T {
|
||||
&self.value
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> Sync for GILProtected<T> where T: Send {}
|
||||
|
|
Loading…
Reference in New Issue