Poisoning is the way to go in the long run. I haven't really thought
about how much of a pain this could be.
On 10/5/19 5:03 PM, Yuya Nishihara wrote:
On Sun, 22 Sep 2019 15:41:40 +0900, Yuya Nishihara wrote:
# HG changeset patch
# User Yuya Nishihara <y...@tcha.org>
# Date 1568674765 -32400
# Tue Sep 17 07:59:25 2019 +0900
# Node ID fcaf01804ac8198d52d141d642d5ef7c935360cc
# Parent 34a355c69f643f15ff46f4524c75137c08a8de3b
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.
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 @@ pub struct PySharedState {
mutably_borrowed: Cell<bool>,
}
+// &PySharedState can be Send because any access to inner cells is
+// synchronized by the GIL.
+unsafe impl Sync for PySharedState {}
Perhaps, this unsafe impl can be removed later.
If we take the generation-poisoning idea, PySharedState will be just
{ generation: AtomicUsize }, which is inherently Sync.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel