Merge pull request #178 from tomaka/update-rustc

Update for changes in Send/Sync traits
This commit is contained in:
tomaka 2014-12-30 08:31:09 +01:00
commit 32faad403b
8 changed files with 41 additions and 4 deletions

View file

@ -38,9 +38,9 @@ git = "https://github.com/servo/rust-core-graphics"
git = "https://github.com/servo/rust-core-graphics" git = "https://github.com/servo/rust-core-graphics"
[target.i686-pc-windows-gnu.dependencies.winapi] [target.i686-pc-windows-gnu.dependencies.winapi]
version = "^0.0.2" version = "^0.0.3"
features = ["gdi32", "kernel32", "user32"] features = ["gdi32", "kernel32", "user32"]
[target.x86_64-pc-windows-gnu.dependencies.winapi] [target.x86_64-pc-windows-gnu.dependencies.winapi]
version = "^0.0.2" version = "^0.0.3"
features = ["gdi32", "kernel32", "user32"] features = ["gdi32", "kernel32", "user32"]

View file

@ -60,6 +60,11 @@ impl HeadlessContext {
} }
} }
#[cfg(feature = "headless")]
unsafe impl Send for HeadlessContext {}
#[cfg(feature = "headless")]
unsafe impl Sync for HeadlessContext {}
impl Window { impl Window {
pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> { pub fn new(builder: WindowBuilder) -> Result<Window, CreationError> {
use std::{mem, ptr}; use std::{mem, ptr};
@ -275,6 +280,9 @@ impl Window {
} }
} }
unsafe impl Send for Window {}
unsafe impl Sync for Window {}
#[cfg(feature = "window")] #[cfg(feature = "window")]
#[deriving(Clone)] #[deriving(Clone)]
pub struct WindowProxy; pub struct WindowProxy;

View file

@ -99,6 +99,9 @@ impl HeadlessContext {
} }
} }
unsafe impl Send for HeadlessContext {}
unsafe impl Sync for HeadlessContext {}
impl Drop for HeadlessContext { impl Drop for HeadlessContext {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {

View file

@ -72,6 +72,11 @@ impl Window {
} }
} }
#[cfg(feature = "window")]
unsafe impl Send for Window {}
#[cfg(feature = "window")]
unsafe impl Sync for Window {}
#[cfg(feature = "window")] #[cfg(feature = "window")]
#[deriving(Clone)] #[deriving(Clone)]
pub struct WindowProxy; pub struct WindowProxy;

View file

@ -18,11 +18,15 @@ use winapi;
/// receive an event for another window. /// receive an event for another window.
thread_local!(static WINDOW: Rc<RefCell<Option<(winapi::HWND, Sender<Event>)>>> = Rc::new(RefCell::new(None))); thread_local!(static WINDOW: Rc<RefCell<Option<(winapi::HWND, Sender<Event>)>>> = Rc::new(RefCell::new(None)));
/// Work-around the fact that HGLRC doesn't implement Send
pub struct ContextHack(pub winapi::HGLRC);
unsafe impl Send for ContextHack {}
pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String, pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: String,
builder_monitor: Option<super::MonitorID>, builder_monitor: Option<super::MonitorID>,
builder_gl_version: Option<(uint, uint)>, builder_debug: bool, builder_gl_version: Option<(uint, uint)>, builder_debug: bool,
builder_vsync: bool, builder_hidden: bool, builder_vsync: bool, builder_hidden: bool,
builder_sharelists: Option<winapi::HGLRC>, builder_multisampling: Option<u16>) builder_sharelists: Option<ContextHack>, builder_multisampling: Option<u16>)
-> Result<Window, CreationError> -> Result<Window, CreationError>
{ {
use std::mem; use std::mem;
@ -38,6 +42,8 @@ pub fn new_window(builder_dimensions: Option<(uint, uint)>, builder_title: Strin
// so we create a new thread dedicated to this window. // so we create a new thread dedicated to this window.
// This is the only safe method. Using `nosend` wouldn't work for non-native runtime. // This is the only safe method. Using `nosend` wouldn't work for non-native runtime.
::std::thread::Thread::spawn(move || { ::std::thread::Thread::spawn(move || {
let builder_sharelists = builder_sharelists.map(|s| s.0);
// registering the window class // registering the window class
let class_name = { let class_name = {
let class_name: Vec<u16> = "Window Class".utf16_units().chain(Some(0).into_iter()) let class_name: Vec<u16> = "Window Class".utf16_units().chain(Some(0).into_iter())

View file

@ -51,6 +51,11 @@ impl HeadlessContext {
} }
} }
#[cfg(feature = "headless")]
unsafe impl Send for HeadlessContext {}
#[cfg(feature = "headless")]
unsafe impl Sync for HeadlessContext {}
/// The Win32 implementation of the main `Window` object. /// The Win32 implementation of the main `Window` object.
pub struct Window { pub struct Window {
/// Main handle for the window. /// Main handle for the window.
@ -75,6 +80,9 @@ pub struct Window {
is_closed: AtomicBool, is_closed: AtomicBool,
} }
unsafe impl Send for Window {}
unsafe impl Sync for Window {}
#[cfg(feature = "window")] #[cfg(feature = "window")]
impl Window { impl Window {
/// See the docs in the crate root file. /// See the docs in the crate root file.
@ -82,7 +90,8 @@ impl Window {
let WindowBuilder { dimensions, title, monitor, gl_version, let WindowBuilder { dimensions, title, monitor, gl_version,
gl_debug, vsync, visible, sharing, multisampling } = builder; gl_debug, vsync, visible, sharing, multisampling } = builder;
init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync, init::new_window(dimensions, title, monitor, gl_version, gl_debug, vsync,
!visible, sharing.map(|w| w.window.context), multisampling) !visible, sharing.map(|w| init::ContextHack(w.window.context)),
multisampling)
} }
} }

View file

@ -62,3 +62,6 @@ impl Drop for HeadlessContext {
unsafe { ffi::OSMesaDestroyContext(self.context) } unsafe { ffi::OSMesaDestroyContext(self.context) }
} }
} }
unsafe impl Send for HeadlessContext {}
unsafe impl Sync for HeadlessContext {}

View file

@ -34,6 +34,9 @@ struct XWindow {
im: ffi::XIM, im: ffi::XIM,
} }
unsafe impl Send for Window {}
unsafe impl Sync for Window {}
impl Drop for XWindow { impl Drop for XWindow {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {