diff --git a/src/sdl2/audio.rs b/src/sdl2/audio.rs index ea1ef50f014..567215865eb 100644 --- a/src/sdl2/audio.rs +++ b/src/sdl2/audio.rs @@ -7,7 +7,6 @@ use std::c_vec::CVec; use libc; use libc::{c_int, size_t, c_void}; use libc::{uint8_t}; -use rustrt::task::Task; use get_error; use rwops::RWops; @@ -246,39 +245,9 @@ pub trait AudioCallback { /// The userdata as seen by the SDL callback. struct AudioCallbackUserdata { - task: AudioCallbackTask, callback: CB } -/// A Task is required to use libstd from SDL's audio callback. -struct AudioCallbackTask { - /// Set to None if there was an error running a previous task. - task: Option> -} - -impl Drop for AudioCallbackTask { - /// Destroy the callback task. - fn drop(&mut self) { - use rustrt::local::Local; - use std::mem::replace; - - // Swap out the task with None in order to own it, since drop() only - // provides a reference. - match replace(&mut self.task, None) { - Some(task) => { - // pop current task - let old_task = Local::take(); - - task.destroy(); - - // put task back - Local::put(old_task); - }, - None => () - }; - } -} - /// A phantom type for retreiving the SDL_AudioFormat of a given generic type. /// All format types are returned as native-endian. /// @@ -329,25 +298,7 @@ extern "C" fn audio_callback_marshall, CB: AudioCallback len: len as uint / size_of::() }); - // Perform a dance to move tasks around without compiler errors - let new_task = match replace(&mut cb_userdata.task.task, None) { - Some(task) => { - let n = task.run(|| { - cb_userdata.callback.callback(buf); - }); - - if n.is_destroyed() { None } - else { Some(n) } - }, - None => { - // Last callback had an error. Fill buffer with silence. - for x in buf.iter_mut() { *x = AudioFormatNum::zero(); } - - None - } - }; - - replace(&mut cb_userdata.task.task, new_task); + cb_userdata.callback.callback(buf); } } @@ -377,11 +328,7 @@ impl, CB: AudioCallback> AudioSpecDesired { } fn callback_to_userdata(callback: CB) -> Box> { - let mut task = box Task::new(None, None); - task.name = Some("SDL audio callback".into_cow()); - box AudioCallbackUserdata { - task: AudioCallbackTask { task: Some(task) }, callback: callback } } @@ -556,8 +503,8 @@ pub struct AudioCVT { owned: bool, } -impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT) -impl_owned_accessors!(AudioCVT, owned) +impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT); +impl_owned_accessors!(AudioCVT, owned); impl Drop for AudioCVT { fn drop(&mut self) { diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 6736c41b460..3dc22d4144d 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -5,7 +5,6 @@ extern crate libc; extern crate collections; -extern crate rustrt; pub use sdl::*; diff --git a/src/sdl2/macros.rs b/src/sdl2/macros.rs index 94e401e4608..167f63e25ce 100644 --- a/src/sdl2/macros.rs +++ b/src/sdl2/macros.rs @@ -9,7 +9,7 @@ macro_rules! impl_raw_accessors( } )+ ) -) +); macro_rules! impl_owned_accessors( ($($t:ty, $owned:ident);+) => ( @@ -20,7 +20,7 @@ macro_rules! impl_owned_accessors( } )+ ) -) +); macro_rules! impl_raw_constructor( ($($t:ty -> $te:ident ($($r:ident:$rt:ty),+));+) => ( @@ -33,4 +33,4 @@ macro_rules! impl_raw_constructor( } )+ ) -) +); diff --git a/src/sdl2/pixels.rs b/src/sdl2/pixels.rs index b1d707a22fb..7f29de9572c 100644 --- a/src/sdl2/pixels.rs +++ b/src/sdl2/pixels.rs @@ -97,7 +97,7 @@ pub struct Palette { raw: *const ll::SDL_Palette } -impl_raw_accessors!(Palette, *const ll::SDL_Palette) +impl_raw_accessors!(Palette, *const ll::SDL_Palette); #[deriving(PartialEq, Clone, Copy)] pub enum Color { @@ -149,8 +149,8 @@ pub struct PixelFormat { raw: *const ll::SDL_PixelFormat } -impl_raw_accessors!(PixelFormat, *const ll::SDL_PixelFormat) -impl_raw_constructor!(PixelFormat -> PixelFormat (raw: *const ll::SDL_PixelFormat)) +impl_raw_accessors!(PixelFormat, *const ll::SDL_PixelFormat); +impl_raw_constructor!(PixelFormat -> PixelFormat (raw: *const ll::SDL_PixelFormat)); #[deriving(Copy, Clone, PartialEq, Show, FromPrimitive)] pub enum PixelFormatFlag { diff --git a/src/sdl2/rwops.rs b/src/sdl2/rwops.rs index d3eeb1cc4f6..6d9fb606c8d 100644 --- a/src/sdl2/rwops.rs +++ b/src/sdl2/rwops.rs @@ -52,8 +52,8 @@ pub struct RWops { close_on_drop: bool } -impl_raw_accessors!(RWops, *const ll::SDL_RWops) -impl_owned_accessors!(RWops, close_on_drop) +impl_raw_accessors!(RWops, *const ll::SDL_RWops); +impl_owned_accessors!(RWops, close_on_drop); /// A structure that provides an abstract interface to stream I/O. impl RWops { diff --git a/src/sdl2/surface.rs b/src/sdl2/surface.rs index 034f3ed4b43..9db7ad699f8 100644 --- a/src/sdl2/surface.rs +++ b/src/sdl2/surface.rs @@ -108,9 +108,9 @@ impl Drop for Surface { } } -impl_raw_accessors!(Surface, *const ll::SDL_Surface) -impl_owned_accessors!(Surface, owned) -impl_raw_constructor!(Surface -> Surface (raw: *const ll::SDL_Surface, owned: bool)) +impl_raw_accessors!(Surface, *const ll::SDL_Surface); +impl_owned_accessors!(Surface, owned); +impl_raw_constructor!(Surface -> Surface (raw: *const ll::SDL_Surface, owned: bool)); impl Surface { pub fn new(surface_flags: SurfaceFlag, width: int, height: int, bpp: int, diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 56c411f4b25..c097d190f7c 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -343,16 +343,16 @@ pub struct Window { impl_raw_accessors!( GLContext, ll::SDL_GLContext; Window, *const ll::SDL_Window -) +); impl_owned_accessors!( GLContext, owned; Window, owned -) +); impl_raw_constructor!( Window -> Window (raw: *const ll::SDL_Window, owned: bool) -) +); impl Drop for Window { fn drop(&mut self) {