mirror of
https://github.com/servo/servo.git
synced 2025-08-01 19:50:30 +01:00
Kill Runnable::is_cancelled ⚔️
This commit is contained in:
parent
c68bc0c145
commit
17a1dd9385
3 changed files with 21 additions and 19 deletions
|
@ -221,24 +221,35 @@ pub struct CancellableRunnable<T: Runnable + Send> {
|
||||||
inner: Box<T>,
|
inner: Box<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Runnable + Send> Runnable for CancellableRunnable<T> {
|
impl<T> CancellableRunnable<T>
|
||||||
|
where
|
||||||
|
T: Runnable + Send,
|
||||||
|
{
|
||||||
fn is_cancelled(&self) -> bool {
|
fn is_cancelled(&self) -> bool {
|
||||||
self.cancelled.as_ref()
|
self.cancelled.as_ref().map_or(false, |cancelled| {
|
||||||
.map(|cancelled| cancelled.load(Ordering::SeqCst))
|
cancelled.load(Ordering::SeqCst)
|
||||||
.unwrap_or(false)
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Runnable for CancellableRunnable<T>
|
||||||
|
where
|
||||||
|
T: Runnable + Send,
|
||||||
|
{
|
||||||
fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) {
|
fn main_thread_handler(self: Box<CancellableRunnable<T>>, script_thread: &ScriptThread) {
|
||||||
|
if !self.is_cancelled() {
|
||||||
self.inner.main_thread_handler(script_thread);
|
self.inner.main_thread_handler(script_thread);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handler(self: Box<CancellableRunnable<T>>) {
|
fn handler(self: Box<CancellableRunnable<T>>) {
|
||||||
|
if !self.is_cancelled() {
|
||||||
self.inner.handler()
|
self.inner.handler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Runnable {
|
pub trait Runnable {
|
||||||
fn is_cancelled(&self) -> bool { false }
|
|
||||||
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
|
fn name(&self) -> &'static str { unsafe { intrinsics::type_name::<Self>() } }
|
||||||
fn handler(self: Box<Self>) {}
|
fn handler(self: Box<Self>) {}
|
||||||
fn main_thread_handler(self: Box<Self>, _script_thread: &ScriptThread) { self.handler(); }
|
fn main_thread_handler(self: Box<Self>, _script_thread: &ScriptThread) { self.handler(); }
|
||||||
|
@ -1281,12 +1292,7 @@ impl ScriptThread {
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(_, runnable)) => {
|
||||||
// The category of the runnable is ignored by the pattern, however
|
// The category of the runnable is ignored by the pattern, however
|
||||||
// it is still respected by profiling (see categorize_msg).
|
// it is still respected by profiling (see categorize_msg).
|
||||||
if !runnable.is_cancelled() {
|
|
||||||
debug!("Running runnable.");
|
|
||||||
runnable.main_thread_handler(self)
|
runnable.main_thread_handler(self)
|
||||||
} else {
|
|
||||||
debug!("Not running cancelled runnable.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) =>
|
MainThreadScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) =>
|
||||||
self.collect_reports(reports_chan),
|
self.collect_reports(reports_chan),
|
||||||
|
|
|
@ -71,8 +71,6 @@ impl fmt::Debug for DOMManipulationTask {
|
||||||
|
|
||||||
impl DOMManipulationTask {
|
impl DOMManipulationTask {
|
||||||
pub fn handle_task(self, script_thread: &ScriptThread) {
|
pub fn handle_task(self, script_thread: &ScriptThread) {
|
||||||
if !self.0.is_cancelled() {
|
|
||||||
self.0.main_thread_handler(script_thread);
|
self.0.main_thread_handler(script_thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -62,8 +62,6 @@ impl fmt::Debug for UserInteractionTask {
|
||||||
|
|
||||||
impl UserInteractionTask {
|
impl UserInteractionTask {
|
||||||
pub fn handle_task(self, script_thread: &ScriptThread) {
|
pub fn handle_task(self, script_thread: &ScriptThread) {
|
||||||
if !self.0.is_cancelled() {
|
|
||||||
self.0.main_thread_handler(script_thread);
|
self.0.main_thread_handler(script_thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue