From ee5a9f133869809385bef96fcded4f22ddcc003f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 6 Jan 2017 15:31:12 -0800 Subject: Replace need for drop_types_in_const with lazy_static --- src/window.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/window.rs') diff --git a/src/window.rs b/src/window.rs index b56b28a0..40729e99 100644 --- a/src/window.rs +++ b/src/window.rs @@ -14,6 +14,7 @@ use std::convert::From; use std::fmt::{self, Display}; use std::ops::Deref; +use std::sync::Mutex; use gl; use glutin; @@ -26,13 +27,13 @@ use glutin; /// /// This will fail horribly if more than one window is created. Don't do that :) fn window_resize_handler(width: u32, height: u32) { - unsafe { - RESIZE_CALLBACK.as_ref().map(|func| func(width, height)); - } + RESIZE_CALLBACK.lock().unwrap().as_ref().map(|func| (*func)(width, height)); } -/// The resize callback invoked by `window_resize_handler` -static mut RESIZE_CALLBACK: Option> = None; +lazy_static! { + /// The resize callback invoked by `window_resize_handler` + static ref RESIZE_CALLBACK: Mutex>> = Mutex::new(None); +} /// Window errors #[derive(Debug)] @@ -238,10 +239,9 @@ impl Window { /// /// This method takes self mutably to ensure there's no race condition /// setting the callback. - pub fn set_resize_callback(&mut self, func: F) { - unsafe { - RESIZE_CALLBACK = Some(Box::new(func)); - } + pub fn set_resize_callback(&mut self, func: F) { + let mut guard = RESIZE_CALLBACK.lock().unwrap(); + *guard = Some(Box::new(func)); } pub fn inner_size_pixels(&self) -> Option>> { -- cgit