lib-misc-utils · crate

parking_lot

Libraryenvironment

Kinogaki's own parking_lot, published under the crates.io name so the frozen wgpu, wgpu-core and wgpu-hal resolve to it through [patch.crates-io].

Repository
lib-misc-utils (kinogaki/lib-misc-utils)
Folder
libs/lib-misc-utils/crates/parking_lot
Source
5 files, 723 lines
Tests
1 file, 263 lines
This crate parking_lot
depends onused by tests alonedependencies for tests alone are listed below, not drawn

What it is

Kinogaki's own parking_lot, published under the crates.io name so the frozen wgpu, wgpu-core and wgpu-hal resolve to it through [patch.crates-io]. It is not upstream parking_lot: it has the lock API those crates call, with parking_lot's semantics where they rely on them:

  • no poisoning: a panic while a lock is held leaves it usable;
  • Condvar waits take the guard by &mut and return a timeout result;
  • RwLock is writer-preferring (task-fair): once a writer waits, new readers wait behind it, so writers are never starved and a thread that reads recursively while a writer waits deadlocks, as with parking_lot. (wgpu-core never re-reads a lock it holds; its lock ranks forbid it.)
  • RwLockReadGuard can be forgotten and its read released later with RwLock::force_unlock_read (wgpu-core's snatch lock does this).

Mutex and Condvar wrap std's. RwLock keeps its state in one atomic word (an uncontended read or write is one compare-exchange) and parks waiters on a std mutex and condition variable; its data cell is the crate's only unsafe code (src/rwlock/cell.rs).

Depends on

None.

Third-party

None.

Used by

None.

Third-party crates using it

wgpu, wgpu-core, wgpu-hal

Modules

Public types and traits

At the crate root

Structs CondvarMutexMutexGuardRwLockRwLockReadGuardRwLockWriteGuardWaitTimeoutResult

By module: 7 public types and traits in 3 modules

condvar CondvarWaitTimeoutResult

mutex MutexMutexGuard

rwlock RwLockRwLockReadGuardRwLockWriteGuard