D6859: rust-cpython: mark PySharedState as Sync so &'PySharedState can be Send (RFC)

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Mon Sep 16 19:27:47 EDT 2019


yuja created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.py_shared_state(py).
  
  I think PySharedState is Sync because any mutation is synchronized by the
  Python GIL, but I'm not pretty sure. I want to know if that's correct before
  moving forward.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6859

AFFECTED FILES
  rust/hg-cpython/src/ref_sharing.rs

CHANGE DETAILS

diff --git a/rust/hg-cpython/src/ref_sharing.rs b/rust/hg-cpython/src/ref_sharing.rs
--- a/rust/hg-cpython/src/ref_sharing.rs
+++ b/rust/hg-cpython/src/ref_sharing.rs
@@ -18,6 +18,10 @@
     mutably_borrowed: Cell<bool>,
 }
 
+// &PySharedState can be Send because any mutation of inner cells is
+// synchronized by the GIL.
+unsafe impl Sync for PySharedState {}
+
 impl PySharedState {
     pub fn borrow_mut<'a, T>(
         &'a self,



To: yuja, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel


More information about the Mercurial-devel mailing list