From 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:33 +0200 Subject: Merging upstream version 125.0.1. Signed-off-by: Daniel Baumann --- servo/components/style/driver.rs | 42 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'servo/components/style/driver.rs') diff --git a/servo/components/style/driver.rs b/servo/components/style/driver.rs index 95447ce08e..a2407cb209 100644 --- a/servo/components/style/driver.rs +++ b/servo/components/style/driver.rs @@ -46,16 +46,28 @@ fn report_statistics(stats: &PerThreadTraversalStatistics) { gecko_stats.mStylesReused += stats.styles_reused; } -fn with_pool_in_place_scope<'scope, R>( +fn with_pool_in_place_scope<'scope>( work_unit_max: usize, pool: Option<&rayon::ThreadPool>, - closure: impl FnOnce(Option<&rayon::ScopeFifo<'scope>>) -> R, -) -> R { + closure: impl FnOnce(Option<&rayon::ScopeFifo<'scope>>) + Send + 'scope, +) { if work_unit_max == 0 || pool.is_none() { - closure(None) + closure(None); } else { - pool.unwrap() - .in_place_scope_fifo(|scope| closure(Some(scope))) + let pool = pool.unwrap(); + pool.in_place_scope_fifo(|scope| { + #[cfg(feature = "gecko")] + debug_assert_eq!( + pool.current_thread_index(), + Some(0), + "Main thread should be the first thread" + ); + if cfg!(feature = "gecko") || pool.current_thread_index().is_some() { + closure(Some(scope)); + } else { + scope.spawn_fifo(|scope| closure(Some(scope))); + } + }); } } @@ -108,6 +120,8 @@ where // Process the nodes breadth-first. This helps keep similar traversal characteristics for the // style sharing cache. let work_unit_max = work_unit_max(); + + let send_root = unsafe { SendNode::new(root.as_node()) }; with_pool_in_place_scope(work_unit_max, pool, |maybe_scope| { let mut tlc = scoped_tls.ensure(parallel::create_thread_local_context); let mut context = StyleContext { @@ -115,22 +129,16 @@ where thread_local: &mut tlc, }; - debug_assert_eq!( - scoped_tls.current_thread_index(), - 0, - "Main thread should be the first thread" - ); - let mut discovered = VecDeque::with_capacity(work_unit_max * 2); - discovered.push_back(unsafe { SendNode::new(root.as_node()) }); + let current_dom_depth = send_root.depth(); + let opaque_root = send_root.opaque(); + discovered.push_back(send_root); parallel::style_trees( &mut context, discovered, - root.as_node().opaque(), + opaque_root, work_unit_max, - PerLevelTraversalData { - current_dom_depth: root.depth(), - }, + PerLevelTraversalData { current_dom_depth }, maybe_scope, traversal, &scoped_tls, -- cgit v1.2.3