Skip to content

Commit 38a13b9

Browse files
teoxoyErichDonGubler
authored andcommitted
refactor: make Snatchable::snatch take _guard by &mut _
1 parent 7ac533a commit 38a13b9

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

wgpu-core/src/device/resource.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Device {
363363
let Some(view) = view.upgrade() else {
364364
continue;
365365
};
366-
let Some(raw_view) = view.raw.snatch(self.snatchable_lock.write()) else {
366+
let Some(raw_view) = view.raw.snatch(&mut self.snatchable_lock.write()) else {
367367
continue;
368368
};
369369

@@ -377,7 +377,8 @@ impl Device {
377377
let Some(bind_group) = bind_group.upgrade() else {
378378
continue;
379379
};
380-
let Some(raw_bind_group) = bind_group.raw.snatch(self.snatchable_lock.write())
380+
let Some(raw_bind_group) =
381+
bind_group.raw.snatch(&mut self.snatchable_lock.write())
381382
else {
382383
continue;
383384
};

wgpu-core/src/present.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ impl Global {
288288
.textures
289289
.remove(texture.tracker_index());
290290
let suf = surface.raw(device.backend()).unwrap();
291-
let exclusive_snatch_guard = device.snatchable_lock.write();
292-
match texture.inner.snatch(exclusive_snatch_guard).unwrap() {
291+
match texture
292+
.inner
293+
.snatch(&mut device.snatchable_lock.write())
294+
.unwrap()
295+
{
293296
resource::TextureInner::Surface { raw, parent_id } => {
294297
if surface_id != parent_id {
295298
log::error!("Presented frame is from a different surface");
@@ -359,8 +362,11 @@ impl Global {
359362
.textures
360363
.remove(texture.tracker_index());
361364
let suf = surface.raw(device.backend());
362-
let exclusive_snatch_guard = device.snatchable_lock.write();
363-
match texture.inner.snatch(exclusive_snatch_guard).unwrap() {
365+
match texture
366+
.inner
367+
.snatch(&mut device.snatchable_lock.write())
368+
.unwrap()
369+
{
364370
resource::TextureInner::Surface { raw, parent_id } => {
365371
if surface_id == parent_id {
366372
unsafe { suf.unwrap().discard_texture(raw) };

wgpu-core/src/resource.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,7 @@ impl Buffer {
737737
let device = &self.device;
738738

739739
let temp = {
740-
let snatch_guard = device.snatchable_lock.write();
741-
let raw = match self.raw.snatch(snatch_guard) {
740+
let raw = match self.raw.snatch(&mut device.snatchable_lock.write()) {
742741
Some(raw) => raw,
743742
None => {
744743
return Err(DestroyError::AlreadyDestroyed);
@@ -1185,8 +1184,7 @@ impl Texture {
11851184
let device = &self.device;
11861185

11871186
let temp = {
1188-
let snatch_guard = device.snatchable_lock.write();
1189-
let raw = match self.inner.snatch(snatch_guard) {
1187+
let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) {
11901188
Some(TextureInner::Native { raw }) => raw,
11911189
Some(TextureInner::Surface { .. }) => {
11921190
return Ok(());

wgpu-core/src/snatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<T> Snatchable<T> {
3838
}
3939

4040
/// Take the value. Requires a the snatchable lock's write guard.
41-
pub fn snatch(&self, _guard: ExclusiveSnatchGuard) -> Option<T> {
41+
pub fn snatch(&self, _guard: &mut ExclusiveSnatchGuard) -> Option<T> {
4242
unsafe { (*self.value.get()).take() }
4343
}
4444

0 commit comments

Comments
 (0)