Move stylo thread pool mutex to servo layout thread crates (#34480)

* Eliminate stylo thread pool mutex

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Reinstate Mutex in the Servo codebase

Signed-off-by: Nico Burns <nico@nicoburns.com>

* Revert back to main Stylo branch

Signed-off-by: Nico Burns <nico@nicoburns.com>

---------

Signed-off-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
Nico Burns 2024-12-05 17:10:27 +13:00 committed by GitHub
parent e4ec84fad1
commit 97f486ad26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 15 deletions

24
Cargo.lock generated
View file

@ -1617,7 +1617,7 @@ dependencies = [
[[package]]
name = "dom"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"bitflags 2.6.0",
"malloc_size_of",
@ -4247,7 +4247,7 @@ dependencies = [
[[package]]
name = "malloc_size_of"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"app_units",
"cssparser",
@ -6196,7 +6196,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.26.0"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"bitflags 2.6.0",
"cssparser",
@ -6484,7 +6484,7 @@ dependencies = [
[[package]]
name = "servo_arc"
version = "0.4.0"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"serde",
"stable_deref_trait",
@ -6493,7 +6493,7 @@ dependencies = [
[[package]]
name = "servo_atoms"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"string_cache",
"string_cache_codegen",
@ -6866,7 +6866,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "static_prefs"
version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
[[package]]
name = "strck"
@ -6925,7 +6925,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "style"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"app_units",
"arrayvec",
@ -6983,7 +6983,7 @@ dependencies = [
[[package]]
name = "style_config"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"lazy_static",
]
@ -6991,7 +6991,7 @@ dependencies = [
[[package]]
name = "style_derive"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"darling",
"proc-macro2",
@ -7021,7 +7021,7 @@ dependencies = [
[[package]]
name = "style_traits"
version = "0.0.1"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"app_units",
"bitflags 2.6.0",
@ -7384,7 +7384,7 @@ dependencies = [
[[package]]
name = "to_shmem"
version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"cssparser",
"servo_arc",
@ -7397,7 +7397,7 @@ dependencies = [
[[package]]
name = "to_shmem_derive"
version = "0.1.0"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#16c1b6858581ab837f04a30cc5bc762ca1cbad23"
source = "git+https://github.com/servo/stylo?branch=2024-11-01#18ca509a7dcfc0f175cddb36b57bc4cd9586f81e"
dependencies = [
"darling",
"proc-macro2",

View file

@ -81,7 +81,7 @@ use style::context::{
use style::dom::{OpaqueNode, ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode};
use style::driver;
use style::error_reporting::RustLogReporter;
use style::global_style_data::{GLOBAL_STYLE_DATA, STYLE_THREAD_POOL};
use style::global_style_data::GLOBAL_STYLE_DATA;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::logical_geometry::LogicalPoint;
use style::media_queries::{Device, MediaList, MediaType};
@ -109,6 +109,14 @@ use webrender_api::units::DevicePixel;
use webrender_api::{units, ColorF, HitTestFlags};
use webrender_traits::CrossProcessCompositorApi;
// This mutex is necessary due to syncronisation issues between two different types of thread-local storage
// which manifest themselves when the layout thread tries to layout iframes in parallel with the main page
//
// See: https://github.com/servo/servo/pull/29792
// And: https://gist.github.com/mukilan/ed57eb61b83237a05fbf6360ec5e33b0
static STYLE_THREAD_POOL: Mutex<&style::global_style_data::STYLE_THREAD_POOL> =
Mutex::new(&style::global_style_data::STYLE_THREAD_POOL);
/// Information needed by layout.
pub struct LayoutThread {
/// The ID of the pipeline that we belong to.

View file

@ -68,7 +68,7 @@ use style::context::{
use style::dom::{OpaqueNode, TElement, TNode};
use style::error_reporting::RustLogReporter;
use style::font_metrics::FontMetrics;
use style::global_style_data::{GLOBAL_STYLE_DATA, STYLE_THREAD_POOL};
use style::global_style_data::GLOBAL_STYLE_DATA;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::media_queries::{Device, MediaList, MediaType};
use style::properties::style_structs::Font;
@ -94,6 +94,14 @@ use webrender_api::units::{DevicePixel, LayoutPixel};
use webrender_api::{units, ExternalScrollId, HitTestFlags};
use webrender_traits::CrossProcessCompositorApi;
// This mutex is necessary due to syncronisation issues between two different types of thread-local storage
// which manifest themselves when the layout thread tries to layout iframes in parallel with the main page
//
// See: https://github.com/servo/servo/pull/29792
// And: https://gist.github.com/mukilan/ed57eb61b83237a05fbf6360ec5e33b0
static STYLE_THREAD_POOL: Mutex<&style::global_style_data::STYLE_THREAD_POOL> =
Mutex::new(&style::global_style_data::STYLE_THREAD_POOL);
/// Information needed by layout.
pub struct LayoutThread {
/// The ID of the pipeline that we belong to.
@ -796,7 +804,7 @@ impl LayoutThread {
self.stylist.flush(&guards, Some(root_element), Some(&map));
let rayon_pool = STYLE_THREAD_POOL.lock().unwrap();
let rayon_pool = STYLE_THREAD_POOL.lock();
let rayon_pool = rayon_pool.pool();
let rayon_pool = rayon_pool.as_ref();