Skip to content

Commit 78341a4

Browse files
committed
[wgpu-core]: Switch to wgpu-types for locking primitives
1 parent add1c74 commit 78341a4

13 files changed

Lines changed: 56 additions & 54 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wgpu-core/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ indexmap.workspace = true
199199
log.workspace = true
200200
macro_rules_attribute = { workspace = true, optional = true }
201201
once_cell = { workspace = true, features = ["std"] }
202-
parking_lot.workspace = true
203202
profiling = { workspace = true, default-features = false }
204203
raw-window-handle.workspace = true
205204
ron = { workspace = true, optional = true }
@@ -211,5 +210,11 @@ thiserror.workspace = true
211210
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
212211
portable-atomic = { workspace = true, optional = true }
213212

213+
[target.'cfg(not(target_family = "wasm"))'.dependencies]
214+
# FIXME: Native platforms mandate `Send`/`Sync`, which is only possible with `std` enabled.
215+
wgpu-types = { workspace = true, features = [
216+
"std",
217+
] }
218+
214219
[build-dependencies]
215220
cfg_aliases.workspace = true

wgpu-core/src/command/compute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use parking_lot::Mutex;
21
use thiserror::Error;
2+
use wgpu_types::sync::Mutex;
33
use wgt::{
44
error::{ErrorType, WebGpuError},
55
BufferAddress, DynamicOffset,

wgpu-core/src/command/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec};
22
use core::{convert::Infallible, fmt, num::NonZeroU32, ops::Range, str};
3-
use parking_lot::Mutex;
43
use smallvec::SmallVec;
4+
use wgpu_types::sync::Mutex;
55

66
use arrayvec::ArrayVec;
77
use thiserror::Error;

wgpu-core/src/device/global.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ impl Global {
712712
// no lock rank here because only one thread should be using compute pass
713713
// and it's only used by id variants of compute pass methods on global
714714
// so no deadlock (or concurrent lock) should happen in practise
715-
let id = fid.assign(Arc::new(parking_lot::Mutex::new(*render_bundle_encoder)));
715+
let id = fid.assign(Arc::new(wgt::sync::Mutex::new(*render_bundle_encoder)));
716716

717717
(id, error)
718718
}

wgpu-core/src/device/resource.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,11 @@ impl ExternalTextureParams {
205205

206206
/// Because all operations are push/swap (no longlived lock),
207207
/// we can have mutex without lock rank
208-
pub(crate) struct DeferredBufferMapPendingClosures(
209-
parking_lot::Mutex<Vec<BufferMapPendingClosure>>,
210-
);
208+
pub(crate) struct DeferredBufferMapPendingClosures(wgt::sync::Mutex<Vec<BufferMapPendingClosure>>);
211209

212210
impl DeferredBufferMapPendingClosures {
213211
pub(crate) fn new() -> Self {
214-
Self(parking_lot::Mutex::new(Vec::new()))
212+
Self(wgt::sync::Mutex::new(Vec::new()))
215213
}
216214

217215
pub(crate) fn push(&self, closure: BufferMapPendingClosure) {

wgpu-core/src/hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ use crate::{
134134
},
135135
};
136136

137-
use parking_lot::Mutex;
137+
use wgpu_types::sync::Mutex;
138138

139139
#[derive(Debug, PartialEq, Eq)]
140140
pub struct HubReport {

wgpu-core/src/lock/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
//!
2828
//! Otherwise, `wgpu-core` uses the [`vanilla`] module's locks.
2929
//!
30-
//! [`Mutex`]: parking_lot::Mutex
31-
//! [`RwLock`]: parking_lot::RwLock
30+
//! [`Mutex`]: wgpu_types::sync::Mutex
31+
//! [`RwLock`]: wgpu_types::sync::RwLock
3232
//! [`SnatchLock`]: crate::snatch::SnatchLock
3333
3434
pub mod rank;

wgpu-core/src/lock/observing.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,30 @@ pub type RankData = Option<HeldLock>;
4242

4343
/// A `Mutex` instrumented for lock acquisition order observation.
4444
///
45-
/// This is just a wrapper around a [`parking_lot::Mutex`], along with
45+
/// This is just a wrapper around a [`wgpu_types::sync::Mutex`], along with
4646
/// its rank in the `wgpu_core` lock ordering.
4747
///
4848
/// For details, see [the module documentation][self].
4949
pub struct Mutex<T> {
50-
inner: parking_lot::Mutex<T>,
50+
inner: wgpu_types::sync::Mutex<T>,
5151
rank: LockRank,
5252
}
5353

5454
/// A guard produced by locking [`Mutex`].
5555
///
56-
/// This is just a wrapper around a [`parking_lot::MutexGuard`], along
56+
/// This is just a wrapper around a [`wgpu_types::sync::MutexGuard`], along
5757
/// with the state needed to track lock acquisition.
5858
///
5959
/// For details, see [the module documentation][self].
6060
pub struct MutexGuard<'a, T> {
61-
inner: parking_lot::MutexGuard<'a, T>,
61+
inner: wgpu_types::sync::MutexGuard<'a, T>,
6262
_state: LockStateGuard,
6363
}
6464

6565
impl<T> Mutex<T> {
6666
pub fn new(rank: LockRank, value: T) -> Mutex<T> {
6767
Mutex {
68-
inner: parking_lot::Mutex::new(value),
68+
inner: wgpu_types::sync::Mutex::new(value),
6969
rank,
7070
}
7171
}
@@ -110,41 +110,41 @@ impl<T: core::fmt::Debug> core::fmt::Debug for Mutex<T> {
110110

111111
/// An `RwLock` instrumented for lock acquisition order observation.
112112
///
113-
/// This is just a wrapper around a [`parking_lot::RwLock`], along with
113+
/// This is just a wrapper around a [`wgpu_types::sync::RwLock`], along with
114114
/// its rank in the `wgpu_core` lock ordering.
115115
///
116116
/// For details, see [the module documentation][self].
117117
pub struct RwLock<T> {
118-
inner: parking_lot::RwLock<T>,
118+
inner: wgpu_types::sync::RwLock<T>,
119119
rank: LockRank,
120120
}
121121

122122
/// A read guard produced by locking [`RwLock`] for reading.
123123
///
124-
/// This is just a wrapper around a [`parking_lot::RwLockReadGuard`], along with
124+
/// This is just a wrapper around a [`wgpu_types::sync::RwLockReadGuard`], along with
125125
/// the state needed to track lock acquisition.
126126
///
127127
/// For details, see [the module documentation][self].
128128
pub struct RwLockReadGuard<'a, T> {
129-
inner: parking_lot::RwLockReadGuard<'a, T>,
129+
inner: wgpu_types::sync::RwLockReadGuard<'a, T>,
130130
_state: LockStateGuard,
131131
}
132132

133133
/// A write guard produced by locking [`RwLock`] for writing.
134134
///
135-
/// This is just a wrapper around a [`parking_lot::RwLockWriteGuard`], along
135+
/// This is just a wrapper around a [`wgpu_types::sync::RwLockWriteGuard`], along
136136
/// with the state needed to track lock acquisition.
137137
///
138138
/// For details, see [the module documentation][self].
139139
pub struct RwLockWriteGuard<'a, T> {
140-
inner: parking_lot::RwLockWriteGuard<'a, T>,
140+
inner: wgpu_types::sync::RwLockWriteGuard<'a, T>,
141141
_state: LockStateGuard,
142142
}
143143

144144
impl<T> RwLock<T> {
145145
pub fn new(rank: LockRank, value: T) -> RwLock<T> {
146146
RwLock {
147-
inner: parking_lot::RwLock::new(value),
147+
inner: wgpu_types::sync::RwLock::new(value),
148148
rank,
149149
}
150150
}

wgpu-core/src/lock/rank.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
/// TODO(<https://github.com/gfx-rs/wgpu/issues/5572>): Resolve invalid
2727
/// acquisitions of DEVICE_COMMAND_INDICES followed by COMMAND_BUFFER_DATA.
2828
///
29-
/// [`Mutex`]: parking_lot::Mutex
30-
/// [`RwLock`]: parking_lot::RwLock
29+
/// [`Mutex`]: wgpu_types::sync::Mutex
30+
/// [`RwLock`]: wgpu_types::sync::RwLock
3131
/// [`SnatchLock`]: crate::snatch::SnatchLock
3232
/// [`CommandBuffer::data`]: crate::command::CommandBuffer::data
3333
#[derive(Debug, Copy, Clone)]

0 commit comments

Comments
 (0)