changeset 43175:a1908eb08342

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.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 17 Sep 2019 07:59:25 +0900
parents 1c675c5fe5fe
children aaec70a5f9a8
files rust/hg-cpython/src/ref_sharing.rs
diffstat 1 files changed, 4 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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,