Skip to content

Commit

Permalink
Use once_cell::Lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Oct 18, 2023
1 parent aa95a5b commit 216e4fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ parking_lot = ">=0.11,<0.13"
profiling = { version = "1", default-features = false }
raw-window-handle = "0.5"
thiserror = "1"
once_cell = "1.18.0"

# backends common
arrayvec = "0.7"
Expand Down
10 changes: 4 additions & 6 deletions wgpu-hal/src/gles/wgl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use glutin_wgl_sys::wgl_extra::{
Wgl, CONTEXT_CORE_PROFILE_BIT_ARB, CONTEXT_DEBUG_BIT_ARB, CONTEXT_FLAGS_ARB,
CONTEXT_PROFILE_MASK_ARB,
};
use once_cell::sync::Lazy;
use parking_lot::{Mutex, MutexGuard};
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use std::{
Expand Down Expand Up @@ -314,12 +315,9 @@ fn get_global_device_context() -> Result<HDC, crate::InstanceError> {
unsafe impl Sync for SendDc {}
unsafe impl Send for SendDc {}

static GLOBAL: Mutex<Option<Result<SendDc, crate::InstanceError>>> = Mutex::new(None);
let mut guard = GLOBAL.lock();
if guard.is_none() {
*guard = Some(create_global_device_context().map(SendDc));
}
guard.clone().unwrap().map(|dc| dc.0)
static GLOBAL: Lazy<Result<SendDc, crate::InstanceError>> =
Lazy::new(|| create_global_device_context().map(SendDc));
GLOBAL.clone().map(|dc| dc.0)
}

impl crate::Instance<super::Api> for Instance {
Expand Down

0 comments on commit 216e4fb

Please sign in to comment.