Skip to content

Commit

Permalink
refactor(hal): s/once_cell::Lazy/std::sync::LazyLock
Browse files Browse the repository at this point in the history
Weaken our dependence on the `once_cell` crate by using functionality
from `std` instead that was upstreamed from `once_cell`, this time with
what's available in Rust 1.80+.

It's not yet possible to eliminate this dependency entirely, but do what
we can for now.
  • Loading branch information
ErichDonGubler committed Jan 22, 2025
1 parent c8e1dfc commit 9cd0ecc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 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 wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ parking_lot.workspace = true
profiling = { workspace = true, default-features = false }
raw-window-handle.workspace = true
thiserror.workspace = true
once_cell.workspace = true
ordered-float = { workspace = true, optional = true }

# backends common
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use glow::HasContext;
use hashbrown::HashMap;
use once_cell::sync::Lazy;
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};

use std::{ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::Arc, time::Duration};
use std::{ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::{Arc, LazyLock}, time::Duration};

/// The amount of time to wait while trying to obtain a lock to the adapter context
const CONTEXT_LOCK_TIMEOUT_SECS: u64 = 1;
Expand Down Expand Up @@ -468,7 +467,8 @@ struct Inner {
// Different calls to `eglGetPlatformDisplay` may return the same `Display`, making it a global
// state of all our `EglContext`s. This forces us to track the number of such context to prevent
// terminating the display if it's currently used by another `EglContext`.
static DISPLAYS_REFERENCE_COUNT: Lazy<Mutex<HashMap<usize, usize>>> = Lazy::new(Default::default);
static DISPLAYS_REFERENCE_COUNT: LazyLock<Mutex<HashMap<usize, usize>>> =
LazyLock::new(Default::default);

fn initialize_display(
egl: &EglInstance,
Expand Down
7 changes: 3 additions & 4 deletions wgpu-hal/src/gles/wgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
ptr,
sync::{
mpsc::{sync_channel, SyncSender},
Arc,
Arc, LazyLock,
},
thread,
time::Duration,
Expand All @@ -17,7 +17,6 @@ use glutin_wgl_sys::wgl_extra::{
CONTEXT_PROFILE_MASK_ARB,
};
use hashbrown::HashSet;
use once_cell::sync::Lazy;
use parking_lot::{Mutex, MutexGuard, RwLock};
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use wgt::InstanceFlags;
Expand Down Expand Up @@ -320,8 +319,8 @@ fn create_global_window_class() -> Result<CString, crate::InstanceError> {
}

fn get_global_window_class() -> Result<CString, crate::InstanceError> {
static GLOBAL: Lazy<Result<CString, crate::InstanceError>> =
Lazy::new(create_global_window_class);
static GLOBAL: LazyLock<Result<CString, crate::InstanceError>> =
LazyLock::new(create_global_window_class);
GLOBAL.clone()
}

Expand Down

0 comments on commit 9cd0ecc

Please sign in to comment.