lib-misc-utils · crate
parking_lot
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
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;
Condvarwaits take the guard by&mutand return a timeout result;RwLockis 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.)RwLockReadGuardcan be forgotten and its read released later withRwLock::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
Modules
condvar(private)A condition variable forMutex, on std'sCondvar.128 linesmutex(private)A mutual exclusion lock without poisoning, on std'sMutex.128 linesrwlock(private)A writer-preferring reader-writer lock.373 linesrwlock::cell(private)The RwLock's data cell: the crate's only unsafe code.72 lines
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
