Mercurial > hg
comparison rust/hg-cpython/src/ref_sharing.rs @ 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 |
comparison
equal
deleted
inserted
replaced
43174:1c675c5fe5fe | 43175:a1908eb08342 |
---|---|
31 pub struct PySharedState { | 31 pub struct PySharedState { |
32 leak_count: Cell<usize>, | 32 leak_count: Cell<usize>, |
33 mutably_borrowed: Cell<bool>, | 33 mutably_borrowed: Cell<bool>, |
34 } | 34 } |
35 | 35 |
36 // &PySharedState can be Send because any access to inner cells is | |
37 // synchronized by the GIL. | |
38 unsafe impl Sync for PySharedState {} | |
39 | |
36 impl PySharedState { | 40 impl PySharedState { |
37 pub fn borrow_mut<'a, T>( | 41 pub fn borrow_mut<'a, T>( |
38 &'a self, | 42 &'a self, |
39 py: Python<'a>, | 43 py: Python<'a>, |
40 pyrefmut: RefMut<'a, T>, | 44 pyrefmut: RefMut<'a, T>, |