Merge pull request #3616 from neachdainn/3615-gilprotected-pyvisit

Enable `GILProtected` access via `PyVisit`
This commit is contained in:
Adam Reichold 2023-12-05 20:43:38 +00:00 committed by GitHub
commit 4baf0235c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1 @@
Add `traverse` method to `GILProtected`

View File

@ -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 {}