refactor(hal): s/once_cell::Lazy/std::sync::LazyLock

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.
This commit is contained in:
Erich Gubler 2024-10-10 14:28:42 -04:00
parent 8774ab53d5
commit 1bd3c7b4ee
3 changed files with 13 additions and 8 deletions

View File

@ -115,7 +115,6 @@ gles = [
"dep:profiling",
"dep:wasm-bindgen",
"dep:web-sys",
"once_cell/std",
"windows/Win32_Graphics_OpenGL",
"windows/Win32_Graphics_Gdi",
"windows/Win32_System_LibraryLoader",

View File

@ -1,13 +1,19 @@
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
use std::{
ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, string::String, sync::Arc, time::Duration,
ffi,
mem::ManuallyDrop,
os::raw,
ptr,
rc::Rc,
string::String,
sync::{Arc, LazyLock},
time::Duration,
vec::Vec,
};
use glow::HasContext;
use hashbrown::HashMap;
use once_cell::sync::Lazy;
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};
/// The amount of time to wait while trying to obtain a lock to the adapter context
@ -474,7 +480,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,

View File

@ -9,7 +9,7 @@ use std::{
string::String,
sync::{
mpsc::{sync_channel, SyncSender},
Arc,
Arc, LazyLock,
},
thread,
time::Duration,
@ -22,7 +22,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;
@ -325,8 +324,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()
}