summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2017-01-06 15:31:12 -0800
committerManish Goregaokar <manishsmail@gmail.com>2017-01-06 20:17:10 -0800
commitee5a9f133869809385bef96fcded4f22ddcc003f (patch)
tree14f1b3aa073046db6555d96ece013df899fc1bf4 /src
parent800b65622cd8881f30d4d02e87c1ba4e4c9d27d2 (diff)
Replace need for drop_types_in_const with lazy_static
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs3
-rw-r--r--src/window.rs18
2 files changed, 11 insertions, 10 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fdfe5f59..46e9dceb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -16,7 +16,6 @@
#![feature(range_contains)]
#![feature(inclusive_range_syntax)]
#![feature(inclusive_range)]
-#![feature(drop_types_in_const)]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]
@@ -36,6 +35,8 @@ extern crate copypasta;
extern crate errno;
extern crate font;
extern crate glutin;
+#[macro_use]
+extern crate lazy_static;
extern crate libc;
extern crate mio;
extern crate notify;
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<Box<Fn(u32, u32)>> = None;
+lazy_static! {
+ /// The resize callback invoked by `window_resize_handler`
+ static ref RESIZE_CALLBACK: Mutex<Option<Box<Fn(u32, u32) + 'static + Send>>> = 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<F: Fn(u32, u32) + 'static>(&mut self, func: F) {
- unsafe {
- RESIZE_CALLBACK = Some(Box::new(func));
- }
+ pub fn set_resize_callback<F: Fn(u32, u32) + 'static + Send>(&mut self, func: F) {
+ let mut guard = RESIZE_CALLBACK.lock().unwrap();
+ *guard = Some(Box::new(func));
}
pub fn inner_size_pixels(&self) -> Option<Size<Pixels<u32>>> {