Skip to content

Commit

Permalink
WIP: refactor(core): use std instead of once_cell
Browse files Browse the repository at this point in the history
Currently only possible on Nightly Rust, because `wgpu-core` needs
[`std::sync::OnceLock::get_or_try_init`].

[`std::sync::OnceLock::get_or_try_init`]: https://doc.rust-lang.org/stable/std/sync/struct.OnceLock.html#method.get_or_try_init
  • Loading branch information
ErichDonGubler committed Jan 22, 2025
1 parent 9cd0ecc commit a98edc5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ nanorand = { version = "0.7", default-features = false, features = ["wyrand"] }
noise = { version = "0.8", git = "https://github.com/Razaekel/noise-rs.git", rev = "c6942d4fb70af26db4441edcf41f90fa115333f2" }
nv-flip = "0.1"
obj = "0.10"
once_cell = "1.20.2"
# Firefox has 3.4.0 vendored, so we allow that version in our dependencies
ordered-float = ">=3,<=4.6"
parking_lot = "0.12.1"
Expand Down
1 change: 0 additions & 1 deletion wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ document-features.workspace = true
hashbrown.workspace = true
indexmap.workspace = true
log.workspace = true
once_cell.workspace = true
parking_lot.workspace = true
profiling = { workspace = true, default-features = false }
raw-window-handle = { workspace = true, optional = true }
Expand Down
7 changes: 3 additions & 4 deletions wgpu-core/src/pool.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::{
hash::Hash,
sync::{Arc, Weak},
sync::{Arc, OnceLock, Weak},
};

use hashbrown::{hash_map::Entry, HashMap};
use once_cell::sync::OnceCell;

use crate::lock::{rank, Mutex};
use crate::FastHashMap;

type SlotInner<V> = Weak<V>;
type ResourcePoolSlot<V> = Arc<OnceCell<SlotInner<V>>>;
type ResourcePoolSlot<V> = Arc<OnceLock<SlotInner<V>>>;

pub struct ResourcePool<K, V> {
inner: Mutex<FastHashMap<K, ResourcePoolSlot<V>>>,
Expand Down Expand Up @@ -52,7 +51,7 @@ impl<K: Clone + Eq + Hash, V> ResourcePool<K, V> {
// No entry exists for this resource.
//
// We know that the resource is not alive, so we can create a new entry.
Entry::Vacant(entry) => Arc::clone(entry.insert(Arc::new(OnceCell::new()))),
Entry::Vacant(entry) => Arc::clone(entry.insert(Arc::new(OnceLock::new()))),
};

drop(map_guard);
Expand Down

0 comments on commit a98edc5

Please sign in to comment.