diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-07-10 08:23:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 08:23:34 -0400 |
commit | 8988d674d0cbea59eaaa8c80f36f29d214682a0b (patch) | |
tree | b661e8bbf9be062af35f5d1eb8eda80de7918dfd /components/script/task_source | |
parent | 2bc70e738b01051a64f2183691e0abd9a0f84072 (diff) | |
parent | 671627e97e20ae4baf728ae6dda61ef6f857c193 (diff) | |
download | servo-8988d674d0cbea59eaaa8c80f36f29d214682a0b.tar.gz servo-8988d674d0cbea59eaaa8c80f36f29d214682a0b.zip |
Auto merge of #21126 - gterzian:tasksource_specific_cancelation, r=jdm
Introduce "per task source" cancellation
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #21119 (github issue number if applicable).
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21126)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/task_source')
-rw-r--r-- | components/script/task_source/dom_manipulation.rs | 4 | ||||
-rw-r--r-- | components/script/task_source/file_reading.rs | 4 | ||||
-rw-r--r-- | components/script/task_source/mod.rs | 27 | ||||
-rw-r--r-- | components/script/task_source/networking.rs | 4 | ||||
-rw-r--r-- | components/script/task_source/performance_timeline.rs | 4 | ||||
-rw-r--r-- | components/script/task_source/user_interaction.rs | 4 |
6 files changed, 41 insertions, 6 deletions
diff --git a/components/script/task_source/dom_manipulation.rs b/components/script/task_source/dom_manipulation.rs index 5b5e55570b4..03b2d85a945 100644 --- a/components/script/task_source/dom_manipulation.rs +++ b/components/script/task_source/dom_manipulation.rs @@ -15,7 +15,7 @@ use std::fmt; use std::result::Result; use std::sync::mpsc::Sender; use task::{TaskCanceller, TaskOnce}; -use task_source::TaskSource; +use task_source::{TaskSource, TaskSourceName}; #[derive(Clone, JSTraceable)] pub struct DOMManipulationTaskSource(pub Sender<MainThreadScriptMsg>, pub PipelineId); @@ -27,6 +27,8 @@ impl fmt::Debug for DOMManipulationTaskSource { } impl TaskSource for DOMManipulationTaskSource { + const NAME: TaskSourceName = TaskSourceName::DOMManipulation; + fn queue_with_canceller<T>( &self, task: T, diff --git a/components/script/task_source/file_reading.rs b/components/script/task_source/file_reading.rs index e94f957234c..8fd3a143eff 100644 --- a/components/script/task_source/file_reading.rs +++ b/components/script/task_source/file_reading.rs @@ -8,7 +8,7 @@ use msg::constellation_msg::PipelineId; use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory, ScriptChan}; use std::sync::Arc; use task::{TaskCanceller, TaskOnce}; -use task_source::TaskSource; +use task_source::{TaskSource, TaskSourceName}; #[derive(JSTraceable)] pub struct FileReadingTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId); @@ -20,6 +20,8 @@ impl Clone for FileReadingTaskSource { } impl TaskSource for FileReadingTaskSource { + const NAME: TaskSourceName = TaskSourceName::FileReading; + fn queue_with_canceller<T>( &self, task: T, diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index 4818ba2c80c..cf605976b46 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + pub mod dom_manipulation; pub mod file_reading; pub mod history_traversal; @@ -10,10 +11,33 @@ pub mod performance_timeline; pub mod user_interaction; use dom::globalscope::GlobalScope; +use enum_iterator::IntoEnumIterator; use std::result::Result; use task::{TaskCanceller, TaskOnce}; +// The names of all task sources, used to differentiate TaskCancellers. +// Note: When adding a task source, update this enum. +// Note: The HistoryTraversalTaskSource is not part of this, +// because it doesn't implement TaskSource. +#[derive(Eq, Hash, IntoEnumIterator, JSTraceable, PartialEq)] +pub enum TaskSourceName { + DOMManipulation, + FileReading, + HistoryTraversal, + Networking, + PerformanceTimeline, + UserInteraction +} + +impl TaskSourceName { + pub fn all() -> Vec<TaskSourceName> { + TaskSourceName::into_enum_iter().collect() + } +} + pub trait TaskSource { + const NAME: TaskSourceName; + fn queue_with_canceller<T>( &self, task: T, @@ -26,6 +50,7 @@ pub trait TaskSource { where T: TaskOnce + 'static, { - self.queue_with_canceller(task, &global.task_canceller()) + let canceller = global.task_canceller(Self::NAME); + self.queue_with_canceller(task, &canceller) } } diff --git a/components/script/task_source/networking.rs b/components/script/task_source/networking.rs index ed192d08003..9058f9653e4 100644 --- a/components/script/task_source/networking.rs +++ b/components/script/task_source/networking.rs @@ -5,7 +5,7 @@ use msg::constellation_msg::PipelineId; use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use task::{TaskCanceller, TaskOnce}; -use task_source::TaskSource; +use task_source::{TaskSource, TaskSourceName}; #[derive(JSTraceable)] pub struct NetworkingTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId); @@ -17,6 +17,8 @@ impl Clone for NetworkingTaskSource { } impl TaskSource for NetworkingTaskSource { + const NAME: TaskSourceName = TaskSourceName::Networking; + fn queue_with_canceller<T>( &self, task: T, diff --git a/components/script/task_source/performance_timeline.rs b/components/script/task_source/performance_timeline.rs index 9f72305b00e..05591bbe71b 100644 --- a/components/script/task_source/performance_timeline.rs +++ b/components/script/task_source/performance_timeline.rs @@ -13,7 +13,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory}; use std::fmt; use std::result::Result; use task::{TaskCanceller, TaskOnce}; -use task_source::TaskSource; +use task_source::{TaskSource, TaskSourceName}; #[derive(JSTraceable)] pub struct PerformanceTimelineTaskSource(pub Box<ScriptChan + Send + 'static>, pub PipelineId); @@ -31,6 +31,8 @@ impl fmt::Debug for PerformanceTimelineTaskSource { } impl TaskSource for PerformanceTimelineTaskSource { + const NAME: TaskSourceName = TaskSourceName::PerformanceTimeline; + fn queue_with_canceller<T>( &self, task: T, diff --git a/components/script/task_source/user_interaction.rs b/components/script/task_source/user_interaction.rs index 12f822afedd..2ace44f1093 100644 --- a/components/script/task_source/user_interaction.rs +++ b/components/script/task_source/user_interaction.rs @@ -15,7 +15,7 @@ use std::fmt; use std::result::Result; use std::sync::mpsc::Sender; use task::{TaskCanceller, TaskOnce}; -use task_source::TaskSource; +use task_source::{TaskSource, TaskSourceName}; #[derive(Clone, JSTraceable)] pub struct UserInteractionTaskSource(pub Sender<MainThreadScriptMsg>, pub PipelineId); @@ -27,6 +27,8 @@ impl fmt::Debug for UserInteractionTaskSource { } impl TaskSource for UserInteractionTaskSource { + const NAME: TaskSourceName = TaskSourceName::UserInteraction; + fn queue_with_canceller<T>( &self, task: T, |