pub trait RwLockExt<T>: Sealed {
type ReadLockResult<'a>
where Self: 'a;
type WriteLockResult<'a>
where Self: 'a;
// Required methods
fn read_py_attached(&self, py: Python<'_>) -> Self::ReadLockResult<'_>;
fn write_py_attached(&self, py: Python<'_>) -> Self::WriteLockResult<'_>;
}Expand description
Extension trait for std::sync::RwLock which helps avoid deadlocks between
the Python interpreter and acquiring the RwLock.
Required Associated Types§
Sourcetype ReadLockResult<'a>
where
Self: 'a
type ReadLockResult<'a> where Self: 'a
The result type returned by the read_py_attached method.
Sourcetype WriteLockResult<'a>
where
Self: 'a
type WriteLockResult<'a> where Self: 'a
The result type returned by the write_py_attached method.
Required Methods§
Sourcefn read_py_attached(&self, py: Python<'_>) -> Self::ReadLockResult<'_>
fn read_py_attached(&self, py: Python<'_>) -> Self::ReadLockResult<'_>
Lock this RwLock for reading in a manner that cannot deadlock with
the Python interpreter.
Before attempting to lock the rwlock, this function detaches from the
Python runtime. When the lock is acquired, it re-attaches to the Python
runtime before returning the ReadLockResult. This avoids deadlocks between
the GIL and other global synchronization events triggered by the Python
interpreter.
Sourcefn write_py_attached(&self, py: Python<'_>) -> Self::WriteLockResult<'_>
fn write_py_attached(&self, py: Python<'_>) -> Self::WriteLockResult<'_>
Lock this RwLock for writing in a manner that cannot deadlock with
the Python interpreter.
Before attempting to lock the rwlock, this function detaches from the
Python runtime. When the lock is acquired, it re-attaches to the Python
runtime before returning the WriteLockResult. This avoids deadlocks between
the GIL and other global synchronization events triggered by the Python
interpreter.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<R, T> RwLockExt<T> for Arc<RwLock<R, T>>where
R: RawRwLock,
Available on crate feature arc_lock only.
impl<R, T> RwLockExt<T> for Arc<RwLock<R, T>>where
R: RawRwLock,
arc_lock only.type ReadLockResult<'a> = ArcRwLockReadGuard<R, T> where Self: 'a
type WriteLockResult<'a> = ArcRwLockWriteGuard<R, T> where Self: 'a
fn read_py_attached(&self, _py: Python<'_>) -> Self::ReadLockResult<'_>
fn write_py_attached(&self, _py: Python<'_>) -> Self::WriteLockResult<'_>
Source§impl<R: RawRwLock, T> RwLockExt<T> for RwLock<R, T>
Available on crate feature lock_api only.
impl<R: RawRwLock, T> RwLockExt<T> for RwLock<R, T>
lock_api only.