mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
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:
parent
8774ab53d5
commit
1bd3c7b4ee
@ -115,7 +115,6 @@ gles = [
|
|||||||
"dep:profiling",
|
"dep:profiling",
|
||||||
"dep:wasm-bindgen",
|
"dep:wasm-bindgen",
|
||||||
"dep:web-sys",
|
"dep:web-sys",
|
||||||
"once_cell/std",
|
|
||||||
"windows/Win32_Graphics_OpenGL",
|
"windows/Win32_Graphics_OpenGL",
|
||||||
"windows/Win32_Graphics_Gdi",
|
"windows/Win32_Graphics_Gdi",
|
||||||
"windows/Win32_System_LibraryLoader",
|
"windows/Win32_System_LibraryLoader",
|
||||||
|
|||||||
@ -1,13 +1,19 @@
|
|||||||
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
|
#![allow(clippy::std_instead_of_alloc, clippy::std_instead_of_core)]
|
||||||
|
|
||||||
use std::{
|
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,
|
vec::Vec,
|
||||||
};
|
};
|
||||||
|
|
||||||
use glow::HasContext;
|
use glow::HasContext;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};
|
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};
|
||||||
|
|
||||||
/// The amount of time to wait while trying to obtain a lock to the adapter context
|
/// 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
|
// 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
|
// 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`.
|
// 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(
|
fn initialize_display(
|
||||||
egl: &EglInstance,
|
egl: &EglInstance,
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use std::{
|
|||||||
string::String,
|
string::String,
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{sync_channel, SyncSender},
|
mpsc::{sync_channel, SyncSender},
|
||||||
Arc,
|
Arc, LazyLock,
|
||||||
},
|
},
|
||||||
thread,
|
thread,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@ -22,7 +22,6 @@ use glutin_wgl_sys::wgl_extra::{
|
|||||||
CONTEXT_PROFILE_MASK_ARB,
|
CONTEXT_PROFILE_MASK_ARB,
|
||||||
};
|
};
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use parking_lot::{Mutex, MutexGuard, RwLock};
|
use parking_lot::{Mutex, MutexGuard, RwLock};
|
||||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
|
||||||
use wgt::InstanceFlags;
|
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> {
|
fn get_global_window_class() -> Result<CString, crate::InstanceError> {
|
||||||
static GLOBAL: Lazy<Result<CString, crate::InstanceError>> =
|
static GLOBAL: LazyLock<Result<CString, crate::InstanceError>> =
|
||||||
Lazy::new(create_global_window_class);
|
LazyLock::new(create_global_window_class);
|
||||||
GLOBAL.clone()
|
GLOBAL.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user