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 31, 2025
1 parent 83c6f2e commit 8dbd01f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 8 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.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ nanorand = { version = "0.7", default-features = false, features = ["wyrand"] }
noise = "0.9"
nv-flip = "0.1"
obj = "0.10"
# NOTE: once_cell/std is *required* for some commonly-used features, selecting this per crate
once_cell = { version = "1.20.2", default-features = false }
# Firefox has 3.4.0 vendored, so we allow that version in our dependencies
ordered-float = { version = ">=3,<=4.6", default-features = false }
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 @@ -123,7 +123,6 @@ document-features.workspace = true
hashbrown.workspace = true
indexmap.workspace = true
log.workspace = true
once_cell = { workspace = true, features = ["std"] }
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 8dbd01f

Please sign in to comment.