Use an RAII guard to join the script task.

This commit is contained in:
Bobby Holley 2015-10-20 15:40:47 -07:00
parent 630b9f8fa0
commit 85596b5510

View file

@ -67,7 +67,7 @@ use std::cell::Cell;
use std::collections::HashMap; use std::collections::HashMap;
use std::collections::hash_state::DefaultState; use std::collections::hash_state::DefaultState;
use std::mem::transmute; use std::mem::transmute;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut, Drop};
use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc::{channel, Sender, Receiver}; use std::sync::mpsc::{channel, Sender, Receiver};
use std::sync::{Arc, Mutex, MutexGuard}; use std::sync::{Arc, Mutex, MutexGuard};
@ -1125,6 +1125,17 @@ impl LayoutTask {
fn handle_reflow<'a>(&'a self, fn handle_reflow<'a>(&'a self,
data: &ScriptReflow, data: &ScriptReflow,
possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>) { possibly_locked_rw_data: &mut Option<MutexGuard<'a, LayoutTaskData>>) {
// Make sure that every return path from this method joins the script task,
// otherwise the script task will panic.
struct AutoJoinScriptTask<'a> { data: &'a ScriptReflow };
impl<'a> Drop for AutoJoinScriptTask<'a> {
fn drop(&mut self) {
self.data.script_join_chan.send(()).unwrap();
}
};
let _ajst = AutoJoinScriptTask { data: data };
// FIXME: Isolate this transmutation into a "bridge" module. // FIXME: Isolate this transmutation into a "bridge" module.
// FIXME(rust#16366): The following line had to be moved because of a // FIXME(rust#16366): The following line had to be moved because of a
// rustc bug. It should be in the next unsafe block. // rustc bug. It should be in the next unsafe block.
@ -1245,9 +1256,6 @@ impl LayoutTask {
ReflowQueryType::NoQuery => {} ReflowQueryType::NoQuery => {}
} }
} }
// Tell script that we're done.
data.script_join_chan.send(()).unwrap();
} }
fn set_visible_rects<'a>(&'a self, fn set_visible_rects<'a>(&'a self,