RwLockExt

Trait RwLockExt 

Source
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§

Source

type ReadLockResult<'a> where Self: 'a

The result type returned by the read_py_attached method.

Source

type WriteLockResult<'a> where Self: 'a

The result type returned by the write_py_attached method.

Required Methods§

Source

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.

Source

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.
Source§

type ReadLockResult<'a> = ArcRwLockReadGuard<R, T> where Self: 'a

Source§

type WriteLockResult<'a> = ArcRwLockWriteGuard<R, T> where Self: 'a

Source§

fn read_py_attached(&self, _py: Python<'_>) -> Self::ReadLockResult<'_>

Source§

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.
Source§

type ReadLockResult<'a> = RwLockReadGuard<'a, R, T> where Self: 'a

Source§

type WriteLockResult<'a> = RwLockWriteGuard<'a, R, T> where Self: 'a

Source§

fn read_py_attached(&self, _py: Python<'_>) -> Self::ReadLockResult<'_>

Source§

fn write_py_attached(&self, _py: Python<'_>) -> Self::WriteLockResult<'_>

Source§

impl<T> RwLockExt<T> for RwLock<T>

Source§

type ReadLockResult<'a> = Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>> where Self: 'a

Source§

type WriteLockResult<'a> = Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>> where Self: 'a

Source§

fn read_py_attached(&self, _py: Python<'_>) -> Self::ReadLockResult<'_>

Source§

fn write_py_attached(&self, _py: Python<'_>) -> Self::WriteLockResult<'_>

Implementors§