INNER CODE UNIT · Rust

lock_read

RyanCodrai/turbovec · turbovec-python/src/lib.rs:321

fn lock_read<T>(lock: &std::sync::RwLock<T>) -> std::sync::RwLockReadGuard<'_, T> {
    lock.read()
        .unwrap_or_else(std::sync::PoisonError::into_inner)
}

/// Write-lock an index; see [`lock_read`] for the poisoning rationale.
fn lock_write<T>(lock: &std::sync::RwLock<T>) -> std::sync::RwLockWriteGuard<'_, T> {
    lock.write()
        .unwrap_or_else(std::sync::PoisonError::into_inner)
}

/// Run `f` under the write lock, for O(1) ops called while attached to
/// the GIL: try the lock without blocking (the uncontended fast path —
/// cheaper than a GIL detach round-trip), and only when another thread
/// holds it detach and acquire it blocking, so a brief removal never
/// stalls every Python thread behind a long writer.
///
/// The work is a closure rather than a returned guard because a guard

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…