rust-cpython: mark PySharedState as Sync so &'PySharedState can be Send
The goal is to store &'static PySharedState in $leaked struct, which allows
us to move the $leaked struct out of the macro. Currently, it depends on
inner.$data_member(py), which can't be generalized.
PySharedState is Sync because any mutation or read operation is synchronized
by the Python GIL, py: Python<'a>, which should guarantee that &'PySharedState
can be sent to another thread.
--- a/rust/hg-cpython/src/ref_sharing.rs Sat Sep 14 23:17:19 2019 +0900
+++ b/rust/hg-cpython/src/ref_sharing.rs Tue Sep 17 07:59:25 2019 +0900
@@ -33,6 +33,10 @@
mutably_borrowed: Cell<bool>,
}
+// &PySharedState can be Send because any access to inner cells is
+// synchronized by the GIL.
+unsafe impl Sync for PySharedState {}
+
impl PySharedState {
pub fn borrow_mut<'a, T>(
&'a self,