Rename Runnable to Task

The changes are:
 * `*Runnable` -> `*Task`;
 * `RunnableMsg` -> `Task`;
 * `RunnableWrapper` -> `TaskCanceller`;
 * `MainThreadRunnable` -> `MainThreadTask`;
 * `wrap_runnable` -> `wrap_task`;
 * `get_runnable_wrapper` -> `task_canceller`;
 * `handler` -> `run`;
 * `main_thread_handler` -> `run_with_script_thread`.
This commit is contained in:
Anthony Ramine 2017-09-16 02:09:26 +02:00
parent 52a6f63608
commit 56117d3185
38 changed files with 370 additions and 332 deletions

View file

@ -4,11 +4,11 @@
use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventRunnable, SimpleEventRunnable};
use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask};
use dom::eventtarget::EventTarget;
use dom::window::Window;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper};
use script_thread::{MainThreadScriptMsg, Task, TaskCanceller};
use servo_atoms::Atom;
use std::fmt;
use std::result::Result;
@ -25,17 +25,17 @@ impl fmt::Debug for DOMManipulationTaskSource {
}
impl TaskSource for DOMManipulationTaskSource {
fn queue_with_wrapper<T>(
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
wrapper: &RunnableWrapper,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Runnable + Send + 'static,
T: Task + Send + 'static,
{
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
ScriptThreadEventCategory::ScriptEvent,
wrapper.wrap_runnable(msg),
canceller.wrap_task(msg),
));
self.0.send(msg).map_err(|_| ())
}
@ -49,21 +49,17 @@ impl DOMManipulationTaskSource {
cancelable: EventCancelable,
window: &Window) {
let target = Trusted::new(target);
let runnable = box EventRunnable {
let task = box EventTask {
target: target,
name: name,
bubbles: bubbles,
cancelable: cancelable,
};
let _ = self.queue(runnable, window.upcast());
let _ = self.queue(task, window.upcast());
}
pub fn queue_simple_event(&self, target: &EventTarget, name: Atom, window: &Window) {
let target = Trusted::new(target);
let runnable = box SimpleEventRunnable {
target: target,
name: name,
};
let _ = self.queue(runnable, window.upcast());
let _ = self.queue(box SimpleEventTask { target, name }, window.upcast());
}
}

View file

@ -5,7 +5,7 @@
use dom::domexception::DOMErrorName;
use dom::filereader::{FileReader, TrustedFileReader, GenerationId, ReadMetaData};
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan};
use script_thread::{Runnable, RunnableWrapper};
use script_thread::{Task, TaskCanceller};
use std::sync::Arc;
use task_source::TaskSource;
@ -19,13 +19,18 @@ impl Clone for FileReadingTaskSource {
}
impl TaskSource for FileReadingTaskSource {
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static {
self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::FileRead,
wrapper.wrap_runnable(msg)))
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Send + Task + 'static,
{
self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::FileRead,
canceller.wrap_task(msg),
))
}
}
@ -41,8 +46,8 @@ impl FileReadingRunnable {
}
}
impl Runnable for FileReadingRunnable {
fn handler(self: Box<FileReadingRunnable>) {
impl Task for FileReadingRunnable {
fn run(self: Box<FileReadingRunnable>) {
self.task.handle_task();
}
}

View file

@ -10,16 +10,19 @@ pub mod performance_timeline;
pub mod user_interaction;
use dom::globalscope::GlobalScope;
use script_thread::{Runnable, RunnableWrapper};
use script_thread::{Task, TaskCanceller};
use std::result::Result;
pub trait TaskSource {
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static;
fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> {
self.queue_with_wrapper(msg, &global.get_runnable_wrapper())
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Send + Task + 'static;
fn queue<T: Task + Send + 'static>(&self, msg: Box<T>, global: &GlobalScope) -> Result<(), ()> {
self.queue_with_canceller(msg, &global.task_canceller())
}
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use script_thread::{Runnable, RunnableWrapper};
use script_thread::{Task, TaskCanceller};
use task_source::TaskSource;
#[derive(JSTraceable)]
@ -16,18 +16,28 @@ impl Clone for NetworkingTaskSource {
}
impl TaskSource for NetworkingTaskSource {
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper)
-> Result<(), ()>
where T: Runnable + Send + 'static {
self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent,
wrapper.wrap_runnable(msg)))
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Send + Task + 'static,
{
self.0.send(CommonScriptMsg::Task(
ScriptThreadEventCategory::NetworkEvent,
canceller.wrap_task(msg),
))
}
}
impl NetworkingTaskSource {
pub fn queue_wrapperless<T: Runnable + Send + 'static>(&self, msg: Box<T>) -> Result<(), ()> {
self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent, msg))
/// This queues a task that will not be cancelled when its associated
/// global scope gets destroyed.
pub fn queue_unconditionally<T>(&self, msg: Box<T>) -> Result<(), ()>
where
T: Task + Send + 'static,
{
self.0.send(CommonScriptMsg::Task(ScriptThreadEventCategory::NetworkEvent, msg))
}
}

View file

@ -10,25 +10,25 @@ use dom::bindings::refcounted::Trusted;
use dom::globalscope::GlobalScope;
use dom::performance::Performance;
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
use script_thread::{Runnable, RunnableWrapper};
use script_thread::{Task, TaskCanceller};
use std::fmt;
use std::result::Result;
use task_source::TaskSource;
pub struct NotifyPerformanceObserverRunnable {
pub struct NotifyPerformanceObserverTask {
owner: Trusted<Performance>,
}
impl NotifyPerformanceObserverRunnable {
impl NotifyPerformanceObserverTask {
pub fn new(owner: Trusted<Performance>) -> Self {
NotifyPerformanceObserverRunnable {
NotifyPerformanceObserverTask {
owner,
}
}
}
impl Runnable for NotifyPerformanceObserverRunnable {
fn handler(self: Box<NotifyPerformanceObserverRunnable>) {
impl Task for NotifyPerformanceObserverTask {
fn run(self: Box<Self>) {
self.owner.root().notify_observers();
}
}
@ -49,13 +49,17 @@ impl fmt::Debug for PerformanceTimelineTaskSource {
}
impl TaskSource for PerformanceTimelineTaskSource {
fn queue_with_wrapper<T>(&self,
msg: Box<T>,
wrapper: &RunnableWrapper) -> Result<(), ()>
where T: Runnable + Send + 'static {
let msg = CommonScriptMsg::RunnableMsg(
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Send + Task + 'static,
{
let msg = CommonScriptMsg::Task(
ScriptThreadEventCategory::PerformanceTimelineTask,
wrapper.wrap_runnable(msg)
canceller.wrap_task(msg)
);
self.0.send(msg).map_err(|_| ())
}
@ -64,7 +68,7 @@ impl TaskSource for PerformanceTimelineTaskSource {
impl PerformanceTimelineTaskSource {
pub fn queue_notification(&self, global: &GlobalScope) {
let owner = Trusted::new(&*global.performance());
let runnable = box NotifyPerformanceObserverRunnable::new(owner);
let _ = self.queue(runnable, global);
let task = box NotifyPerformanceObserverTask::new(owner);
let _ = self.queue(task, global);
}
}

View file

@ -4,11 +4,11 @@
use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventRunnable};
use dom::event::{EventBubbles, EventCancelable, EventTask};
use dom::eventtarget::EventTarget;
use dom::window::Window;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Runnable, RunnableWrapper};
use script_thread::{MainThreadScriptMsg, Task, TaskCanceller};
use servo_atoms::Atom;
use std::fmt;
use std::result::Result;
@ -25,17 +25,17 @@ impl fmt::Debug for UserInteractionTaskSource {
}
impl TaskSource for UserInteractionTaskSource {
fn queue_with_wrapper<T>(
fn queue_with_canceller<T>(
&self,
msg: Box<T>,
wrapper: &RunnableWrapper,
canceller: &TaskCanceller,
) -> Result<(), ()>
where
T: Runnable + Send + 'static,
T: Task + Send + 'static,
{
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::RunnableMsg(
let msg = MainThreadScriptMsg::Common(CommonScriptMsg::Task(
ScriptThreadEventCategory::InputEvent,
wrapper.wrap_runnable(msg),
canceller.wrap_task(msg),
));
self.0.send(msg).map_err(|_| ())
}
@ -49,12 +49,7 @@ impl UserInteractionTaskSource {
cancelable: EventCancelable,
window: &Window) {
let target = Trusted::new(target);
let runnable = box EventRunnable {
target: target,
name: name,
bubbles: bubbles,
cancelable: cancelable,
};
let _ = self.queue(runnable, window.upcast());
let task = box EventTask { target, name, bubbles, cancelable };
let _ = self.queue(task, window.upcast());
}
}