aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/parallel.rs
diff options
context:
space:
mode:
authorBobby Holley <bobbyholley@gmail.com>2016-12-16 11:50:11 -0800
committerBobby Holley <bobbyholley@gmail.com>2016-12-21 11:10:39 -0800
commitc5f01fe3b89c2a381fb891e9728fa2951b87a747 (patch)
treecca5add7c82e7f24255f4706696c02f2ed5bce3f /components/layout/parallel.rs
parent8f7f62f8104bf576c38f7cfa1fedfaf2c51c0049 (diff)
downloadservo-c5f01fe3b89c2a381fb891e9728fa2951b87a747.tar.gz
servo-c5f01fe3b89c2a381fb891e9728fa2951b87a747.zip
Introduce and use Scoped TLS.
It turns out that it's problematic to embed ThreadLocalStyleContext within LayoutContext, because parameterizing the former on TElement (which we do in the next patch) infects all the traversal stuff with the trait parameters, which we don't really want. In general, it probably makes sense to use separate scoped TLS types for the separate DOM and Flow tree passes, so we can add a different ScopedTLS type for the Flow pass if we ever need it. We also reorder the |scope| and |shared| parameters in parallel.rs, because it aligns more with the order in style/parallel.rs. I did this when I was adding a TLS parameter to all these functions, which I realized we don't need for now.
Diffstat (limited to 'components/layout/parallel.rs')
-rw-r--r--components/layout/parallel.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index 505afa7897f..a51f585eb3c 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -8,8 +8,7 @@
#![allow(unsafe_code)]
-use context::{LayoutContext, SharedLayoutContext, ThreadLocalLayoutContext};
-use context::create_or_get_local_context;
+use context::{LayoutContext, SharedLayoutContext};
use flow::{self, Flow, MutableFlowUtils, PostorderFlowTraversal, PreorderFlowTraversal};
use flow_ref::FlowRef;
use profile_traits::time::{self, TimerMetadata, profile};
@@ -51,7 +50,7 @@ pub fn borrowed_flow_to_unsafe_flow(flow: &Flow) -> UnsafeFlow {
}
pub type ChunkedFlowTraversalFunction<'scope> =
- extern "Rust" fn(Box<[UnsafeFlow]>, &'scope SharedLayoutContext, &rayon::Scope<'scope>);
+ extern "Rust" fn(Box<[UnsafeFlow]>, &rayon::Scope<'scope>, &'scope SharedLayoutContext);
pub type FlowTraversalFunction = extern "Rust" fn(UnsafeFlow, &LayoutContext);
@@ -133,23 +132,22 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal {
trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
fn run_parallel<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>);
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext);
fn should_record_thread_ids(&self) -> bool;
#[inline(always)]
fn run_parallel_helper<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- shared: &'scope SharedLayoutContext,
scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext,
top_down_func: ChunkedFlowTraversalFunction<'scope>,
bottom_up_func: FlowTraversalFunction)
{
- let tlc = create_or_get_local_context(shared);
- let context = LayoutContext::new(&shared, &*tlc);
-
let mut discovered_child_flows = vec![];
+ let context = LayoutContext::new(&shared);
+
for unsafe_flow in unsafe_flows {
let mut had_children = false;
unsafe {
@@ -187,7 +185,7 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
let nodes = chunk.iter().cloned().collect::<Vec<_>>().into_boxed_slice();
scope.spawn(move |scope| {
- top_down_func(nodes, shared, scope);
+ top_down_func(nodes, scope, shared);
});
}
}
@@ -196,12 +194,12 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal {
impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
fn run_parallel<'scope>(&self,
unsafe_flows: &[UnsafeFlow],
- layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>)
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext)
{
self.run_parallel_helper(unsafe_flows,
- layout_context,
scope,
+ shared,
assign_inline_sizes,
assign_block_sizes_and_store_overflow)
}
@@ -214,12 +212,12 @@ impl<'a> ParallelPreorderFlowTraversal for AssignISizes<'a> {
impl<'a> ParallelPostorderFlowTraversal for AssignBSizes<'a> {}
fn assign_inline_sizes<'scope>(unsafe_flows: Box<[UnsafeFlow]>,
- shared_layout_context: &'scope SharedLayoutContext,
- scope: &rayon::Scope<'scope>) {
+ scope: &rayon::Scope<'scope>,
+ shared: &'scope SharedLayoutContext) {
let assign_inline_sizes_traversal = AssignISizes {
- shared_context: &shared_layout_context.style_context,
+ shared_context: &shared.style_context,
};
- assign_inline_sizes_traversal.run_parallel(&unsafe_flows, shared_layout_context, scope)
+ assign_inline_sizes_traversal.run_parallel(&unsafe_flows, scope, shared)
}
fn assign_block_sizes_and_store_overflow(
@@ -238,8 +236,7 @@ pub fn traverse_flow_tree_preorder(
shared: &SharedLayoutContext,
queue: &rayon::ThreadPool) {
if opts::get().bubble_inline_sizes_separately {
- let tlc = ThreadLocalLayoutContext::new(shared);
- let context = LayoutContext::new(shared, &*tlc);
+ let context = LayoutContext::new(shared);
let bubble_inline_sizes = BubbleISizes { layout_context: &context };
root.traverse_postorder(&bubble_inline_sizes);
}
@@ -250,7 +247,7 @@ pub fn traverse_flow_tree_preorder(
rayon::scope(move |scope| {
profile(time::ProfilerCategory::LayoutParallelWarmup,
profiler_metadata, time_profiler_chan, move || {
- assign_inline_sizes(nodes, &shared, scope);
+ assign_inline_sizes(nodes, scope, &shared);
});
});
});