Skip to content

Commit

Permalink
refactor: make Snatchable::snatch take _guard by &mut _
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored and ErichDonGubler committed Sep 19, 2024
1 parent 1354f18 commit 0410f67
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl Device {
let Some(view) = view.upgrade() else {
continue;
};
let Some(raw_view) = view.raw.snatch(self.snatchable_lock.write()) else {
let Some(raw_view) = view.raw.snatch(&mut self.snatchable_lock.write()) else {
continue;
};

Expand All @@ -377,7 +377,8 @@ impl Device {
let Some(bind_group) = bind_group.upgrade() else {
continue;
};
let Some(raw_bind_group) = bind_group.raw.snatch(self.snatchable_lock.write())
let Some(raw_bind_group) =
bind_group.raw.snatch(&mut self.snatchable_lock.write())
else {
continue;
};
Expand Down
14 changes: 10 additions & 4 deletions wgpu-core/src/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ impl Global {
.textures
.remove(texture.tracker_index());
let suf = surface.raw(device.backend()).unwrap();
let exclusive_snatch_guard = device.snatchable_lock.write();
match texture.inner.snatch(exclusive_snatch_guard).unwrap() {
match texture
.inner
.snatch(&mut device.snatchable_lock.write())
.unwrap()
{
resource::TextureInner::Surface { raw, parent_id } => {
if surface_id != parent_id {
log::error!("Presented frame is from a different surface");
Expand Down Expand Up @@ -359,8 +362,11 @@ impl Global {
.textures
.remove(texture.tracker_index());
let suf = surface.raw(device.backend());
let exclusive_snatch_guard = device.snatchable_lock.write();
match texture.inner.snatch(exclusive_snatch_guard).unwrap() {
match texture
.inner
.snatch(&mut device.snatchable_lock.write())
.unwrap()
{
resource::TextureInner::Surface { raw, parent_id } => {
if surface_id == parent_id {
unsafe { suf.unwrap().discard_texture(raw) };
Expand Down
6 changes: 2 additions & 4 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,7 @@ impl Buffer {
let device = &self.device;

let temp = {
let snatch_guard = device.snatchable_lock.write();
let raw = match self.raw.snatch(snatch_guard) {
let raw = match self.raw.snatch(&mut device.snatchable_lock.write()) {
Some(raw) => raw,
None => {
return Err(DestroyError::AlreadyDestroyed);
Expand Down Expand Up @@ -1185,8 +1184,7 @@ impl Texture {
let device = &self.device;

let temp = {
let snatch_guard = device.snatchable_lock.write();
let raw = match self.inner.snatch(snatch_guard) {
let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) {
Some(TextureInner::Native { raw }) => raw,
Some(TextureInner::Surface { .. }) => {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion wgpu-core/src/snatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<T> Snatchable<T> {
}

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

Expand Down

0 comments on commit 0410f67

Please sign in to comment.