Merge pull request #3000 from Ms2ger/rendertask

Use spawn_named_with_send_on_failure for the RenderTask; r=Manishearth
This commit is contained in:
Ms2ger 2014-08-06 09:43:42 +02:00
commit e942cd901e
4 changed files with 17 additions and 23 deletions

View file

@ -19,9 +19,6 @@ use layers::platform::surface::{NativePaintingGraphicsContext, NativeSurface};
use layers::platform::surface::{NativeSurfaceMethods};
use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use layers;
use native;
use rustrt::task;
use rustrt::task::TaskOpts;
use servo_msg::compositor_msg::{Epoch, IdleRenderState, LayerId};
use servo_msg::compositor_msg::{LayerMetadata, RenderListener, RenderingRenderState, ScrollPolicy};
use servo_msg::constellation_msg::{ConstellationChan, Failure, FailureMsg, PipelineId};
@ -30,6 +27,7 @@ use servo_msg::platform::surface::NativeSurfaceAzureMethods;
use servo_util::geometry;
use servo_util::opts::Opts;
use servo_util::smallvec::{SmallVec, SmallVec1};
use servo_util::task::spawn_named_with_send_on_failure;
use servo_util::time::{TimeProfilerChan, profile};
use servo_util::time;
use std::comm::{Receiver, Sender, channel};
@ -161,17 +159,7 @@ impl<C:RenderListener + Send> RenderTask<C> {
let ConstellationChan(c) = constellation_chan.clone();
let fc = font_cache_task.clone();
let mut task_opts = TaskOpts::new();
task_opts.name = Some("RenderTask".into_maybe_owned());
task_opts.on_exit = Some(proc(result: task::Result) {
match result {
Ok(()) => {},
Err(..) => {
c.send(FailureMsg(failure_msg));
}
}
});
native::task::spawn_opts(task_opts, proc() {
spawn_named_with_send_on_failure("RenderTask", proc() {
{ // Ensures RenderTask and graphics context are destroyed before shutdown msg
let native_graphics_context = compositor.get_graphics_metadata().map(
|md| NativePaintingGraphicsContext::from_metadata(&md));
@ -213,7 +201,7 @@ impl<C:RenderListener + Send> RenderTask<C> {
debug!("render_task: shutdown_chan send");
shutdown_chan.send(());
});
}, FailureMsg(failure_msg), c, true);
}
fn start(&mut self) {

View file

@ -304,7 +304,7 @@ impl LayoutTaskFactory for LayoutTask {
layout.start();
}
shutdown_chan.send(());
}, FailureMsg(failure_msg), con_chan);
}, FailureMsg(failure_msg), con_chan, false);
}
}

View file

@ -321,7 +321,7 @@ impl ScriptTask {
// This must always be the very last operation performed before the task completes
failsafe.neuter();
}, FailureMsg(failure_msg), const_chan);
}, FailureMsg(failure_msg), const_chan, false);
}
/// Handle incoming control messages.

View file

@ -6,6 +6,7 @@ use std::str::IntoMaybeOwned;
use std::task;
use std::comm::Sender;
use std::task::TaskBuilder;
use native::task::NativeTaskBuilder;
pub fn spawn_named<S: IntoMaybeOwned<'static>>(name: S, f: proc():Send) {
let builder = task::TaskBuilder::new().named(name);
@ -14,15 +15,20 @@ pub fn spawn_named<S: IntoMaybeOwned<'static>>(name: S, f: proc():Send) {
/// Arrange to send a particular message to a channel if the task built by
/// this `TaskBuilder` fails.
pub fn spawn_named_with_send_on_failure<T: Send>(name: &str,
pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
f: proc(): Send,
msg: T,
dest: Sender<T>) {
let name = name.to_string();
let future_result = TaskBuilder::new().named(name.clone()).try_future(f);
dest: Sender<T>,
native: bool) {
let future_result = if native {
TaskBuilder::new().named(name).native().try_future(f)
} else {
TaskBuilder::new().named(name).try_future(f)
};
let watch_name = format!("{:s}Watcher", name);
spawn_named(watch_name, proc() {
let watched_name = name.to_string();
let watcher_name = format!("{:s}Watcher", watched_name);
TaskBuilder::new().named(watcher_name).spawn(proc() {
match future_result.unwrap() {
Ok(()) => (),
Err(..) => {