diff --git a/src/components/gfx/render_task.rs b/src/components/gfx/render_task.rs index fad3a76aae2..0ef051f1413 100644 --- a/src/components/gfx/render_task.rs +++ b/src/components/gfx/render_task.rs @@ -59,19 +59,12 @@ pub fn BufferRequest(screen_rect: Rect, page_rect: Rect) -> BufferReq } #[deriving(Clone)] -pub struct RenderChan { - chan: SharedChan>, -} - +pub struct RenderChan{chan:SharedChan>} impl RenderChan { pub fn new(chan: Chan>) -> RenderChan { - RenderChan { - chan: SharedChan::new(chan), - } - } - pub fn send(&self, msg: Msg) { - self.chan.send(msg); + RenderChan{chan:SharedChan::new(chan)} } + pub fn send(&self, msg: Msg) { self.chan.send(msg) } } struct RenderTask { diff --git a/src/components/main/servo.rc b/src/components/main/servo.rc index ff68e9fb29c..a06330973b2 100755 --- a/src/components/main/servo.rc +++ b/src/components/main/servo.rc @@ -47,7 +47,7 @@ use gfx::opts; use servo_net::image_cache_task::ImageCacheTask; use servo_net::resource_task::ResourceTask; -use servo_util::time::{Profiler, ProfilerChan, PrintMsg}; +use servo_util::time::{Profiler, ProfilerChan}; pub use gfx::opts::Opts; pub use gfx::text; @@ -56,7 +56,7 @@ use std::comm; #[cfg(not(test))] use std::os; use std::rt::rtio::RtioTimer; -use std::rt::io::timer::Timer; +use std::task::spawn_with; #[path="compositing/mod.rs"] pub mod compositing; @@ -127,38 +127,19 @@ fn start(argc: int, argv: **u8, crate_map: *u8) -> int { fn run(opts: Opts) { let (shutdown_port, shutdown_chan) = comm::stream(); - let (profiler_port, profiler_chan) = comm::stream(); - let (compositor_port, compositor_chan) = comm::stream(); + let (profiler_port, profiler_chan) = special_stream!(ProfilerChan); + let (compositor_port, compositor_chan) = special_stream!(CompositorChan); - let profiler_chan = ProfilerChan::new(profiler_chan); - Profiler::create(profiler_port); - do opts.profiler_period.map |&period| { - let profiler_chan = profiler_chan.clone(); - let period = (period * 1000f) as u64; - do spawn { - let mut tm = Timer::new().unwrap(); - loop { - tm.sleep(period); - profiler_chan.send(PrintMsg); - } - } - }; - let compositor_chan = CompositorChan::new(compositor_chan); - let profiler_chan_clone = profiler_chan.clone(); + Profiler::create(profiler_port, profiler_chan.clone(), opts.profiler_period); - let opts_clone = opts.clone(); - - do spawn { - let profiler_chan = profiler_chan_clone.clone(); - let compositor_chan = compositor_chan.clone(); - - let opts = &opts_clone.clone(); + do spawn_with((profiler_chan.clone(), compositor_chan, opts.clone())) + |(profiler_chan, compositor_chan, opts)| { + let opts = &opts; // Create a Servo instance. - let resource_task = ResourceTask(); let image_cache_task = ImageCacheTask(resource_task.clone()); - let constellation_chan = Constellation::start(compositor_chan.clone(), + let constellation_chan = Constellation::start(compositor_chan, opts, resource_task, image_cache_task, diff --git a/src/components/msg/constellation_msg.rs b/src/components/msg/constellation_msg.rs index 7724d53c429..1e61114e3b1 100644 --- a/src/components/msg/constellation_msg.rs +++ b/src/components/msg/constellation_msg.rs @@ -12,18 +12,10 @@ use geom::size::Size2D; use geom::rect::Rect; #[deriving(Clone)] -pub struct ConstellationChan { - chan: SharedChan, -} - +pub struct ConstellationChan(SharedChan); impl ConstellationChan { pub fn new(chan: Chan) -> ConstellationChan { - ConstellationChan { - chan: SharedChan::new(chan), - } - } - pub fn send(&self, msg: Msg) { - self.chan.send(msg); + ConstellationChan(SharedChan::new(chan)) } } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index a7bae87a618..7c60da4d6c5 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -30,6 +30,7 @@ use std::int; use std::libc; use std::rt::rtio::RtioTimer; use std::rt::io::timer::Timer; +use std::task::spawn_with; use js::jsapi::JSVal; pub enum TimerControlMsg { @@ -198,21 +199,20 @@ impl Window { compositor: @ScriptListener, image_cache_task: ImageCacheTask) -> @mut Window { - let script_chan_clone = script_chan.clone(); let win = @mut Window { page: page, - script_chan: script_chan, + script_chan: script_chan.clone(), compositor: compositor, wrapper: WrapperCache::new(), timer_chan: { let (timer_port, timer_chan) = comm::stream::(); let id = page.id.clone(); - do spawn { + do spawn_with(script_chan) |script_chan| { loop { match timer_port.recv() { TimerMessage_Close => break, - TimerMessage_Fire(td) => script_chan_clone.chan.send(FireTimerMsg(id, td)), - TimerMessage_TriggerExit => script_chan_clone.chan.send(ExitMsg), + TimerMessage_Fire(td) => script_chan.send(FireTimerMsg(id, td)), + TimerMessage_TriggerExit => script_chan.send(ExitMsg), } } } diff --git a/src/components/script/layout_interface.rs b/src/components/script/layout_interface.rs index 47f9c1ac362..ce7e6b5bd36 100644 --- a/src/components/script/layout_interface.rs +++ b/src/components/script/layout_interface.rs @@ -111,17 +111,9 @@ pub struct Reflow { /// Encapsulates a channel to the layout task. #[deriving(Clone)] -pub struct LayoutChan { - chan: SharedChan, -} - +pub struct LayoutChan(SharedChan); impl LayoutChan { pub fn new(chan: Chan) -> LayoutChan { - LayoutChan { - chan: SharedChan::new(chan), - } - } - pub fn send(&self, msg: Msg) { - self.chan.send(msg); + LayoutChan(SharedChan::new(chan)) } } diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index 55311b5cf2a..01960196c81 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -83,20 +83,11 @@ pub struct NewLayoutInfo { /// Encapsulates external communication with the script task. #[deriving(Clone)] -pub struct ScriptChan { - /// The channel used to send messages to the script task. - chan: SharedChan, -} - +pub struct ScriptChan(SharedChan); impl ScriptChan { /// Creates a new script chan. pub fn new(chan: Chan) -> ScriptChan { - ScriptChan { - chan: SharedChan::new(chan) - } - } - pub fn send(&self, msg: ScriptMsg) { - self.chan.send(msg); + ScriptChan(SharedChan::new(chan)) } } diff --git a/src/components/util/time.rs b/src/components/util/time.rs index a847bef12c7..9b9f54139ef 100644 --- a/src/components/util/time.rs +++ b/src/components/util/time.rs @@ -3,27 +3,21 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // Timing functions. -use extra::time::precise_time_ns; -use std::cell::Cell; use std::comm::{Port, SharedChan}; -use extra::sort::tim_sort; use std::iterator::AdditiveIterator; +use std::rt::io::timer::Timer; +use std::task::spawn_with; + +use extra::sort::tim_sort; +use extra::time::precise_time_ns; use extra::treemap::TreeMap; // front-end representation of the profiler used to communicate with the profiler #[deriving(Clone)] -pub struct ProfilerChan { - chan: SharedChan, -} - +pub struct ProfilerChan(SharedChan); impl ProfilerChan { pub fn new(chan: Chan) -> ProfilerChan { - ProfilerChan { - chan: SharedChan::new(chan), - } - } - pub fn send(&self, msg: ProfilerMsg) { - self.chan.send(msg); + ProfilerChan(SharedChan::new(chan)) } } @@ -101,11 +95,31 @@ pub struct Profiler { } impl Profiler { - pub fn create(port: Port) { - let port = Cell::new(port); - do spawn { - let mut profiler = Profiler::new(port.take()); - profiler.start(); + pub fn create(port: Port, chan: ProfilerChan, period: Option) { + match period { + Some(period) => { + let period = (period * 1000f) as u64; + do spawn { + let mut timer = Timer::new().unwrap(); + loop { + timer.sleep(period); + if !chan.try_send(PrintMsg) { + break; + } + } + } + // Spawn the profiler + do spawn_with(port) |port| { + let mut profiler = Profiler::new(port); + profiler.start(); + } + } + None => { + // no-op to handle profiler messages when the profiler is inactive + do spawn_with(port) |port| { + while port.try_recv().is_some() {} + } + } } }