Layout-2020: Serialize access to stylo thread pool.

When rendering a page containing an iframe, layout 2020
creates parallel 'Layout' threads which share workers
in the stylo thread pool.

Because of the way the 'StyleSharingCache' is designed
using TLS for storage of the LRU cache, this leads to
a double borrow of the cache when both layout threads
run concurrently.

More details about the issue can be found here:
https://gist.github.com/mukilan/ed57eb61b83237a05fbf6360ec5e33b0

This PR is a workaround until we find a more elegant/optimal
design that also can work for gecko. The fix for now is
simply to not allow multiple layouts in parallel.

Signed-off-by: Mukilan Thiyagarajan <me@mukilan.in>
This commit is contained in:
Mukilan Thiyagarajan 2023-05-24 21:25:37 +05:30
parent 43ebf6c82c
commit 05239f879e
3 changed files with 17 additions and 19 deletions

View file

@ -16,6 +16,7 @@ use parking_lot::{RwLock, RwLockReadGuard};
use rayon;
use std::env;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Mutex;
/// Global style data
pub struct GlobalStyleData {
@ -74,7 +75,7 @@ impl StyleThreadPool {
}
{
// Drop the pool.
let _ = STYLE_THREAD_POOL.style_thread_pool.write().take();
let _ = STYLE_THREAD_POOL.lock().unwrap().style_thread_pool.write().take();
}
// Spin until all our threads are done. This will usually be pretty
// fast, as on shutdown there should be basically no threads left
@ -104,7 +105,7 @@ impl StyleThreadPool {
lazy_static! {
/// Global thread pool
pub static ref STYLE_THREAD_POOL: StyleThreadPool = {
pub static ref STYLE_THREAD_POOL: Mutex<StyleThreadPool> = {
let stylo_threads = env::var("STYLO_THREADS")
.map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS value"));
let mut num_threads = match stylo_threads {
@ -157,14 +158,14 @@ lazy_static! {
workers.ok()
};
StyleThreadPool {
Mutex::new(StyleThreadPool {
num_threads: if num_threads > 0 {
Some(num_threads)
} else {
None
},
style_thread_pool: RwLock::new(pool),
}
})
};
/// Global style data