mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Explicitly register rayon threads, rather than assuming that as the default.
MozReview-Commit-ID: E4kUyy8HjmV
This commit is contained in:
parent
531397ff15
commit
90e9bbbadc
3 changed files with 10 additions and 9 deletions
|
@ -461,7 +461,8 @@ impl LayoutThread {
|
||||||
ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)));
|
ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0)));
|
||||||
|
|
||||||
let configuration =
|
let configuration =
|
||||||
rayon::Configuration::new().num_threads(layout_threads);
|
rayon::Configuration::new().num_threads(layout_threads)
|
||||||
|
.start_handler(|_| thread_state::initialize_layout_worker_thread());
|
||||||
let parallel_traversal = if layout_threads > 1 {
|
let parallel_traversal = if layout_threads > 1 {
|
||||||
Some(rayon::ThreadPool::new(configuration).expect("ThreadPool creation failed"))
|
Some(rayon::ThreadPool::new(configuration).expect("ThreadPool creation failed"))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,6 +15,7 @@ use shared_lock::SharedRwLock;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
|
use thread_state;
|
||||||
|
|
||||||
/// Global style data
|
/// Global style data
|
||||||
pub struct GlobalStyleData {
|
pub struct GlobalStyleData {
|
||||||
|
@ -39,6 +40,7 @@ fn thread_name(index: usize) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn thread_startup(index: usize) {
|
fn thread_startup(index: usize) {
|
||||||
|
thread_state::initialize_layout_worker_thread();
|
||||||
unsafe {
|
unsafe {
|
||||||
Gecko_SetJemallocThreadLocalArena(true);
|
Gecko_SetJemallocThreadLocalArena(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,6 @@ macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => (
|
||||||
}
|
}
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
static TYPES: &'static [ThreadState] =
|
|
||||||
&[ $( $flag ),* ];
|
|
||||||
));
|
));
|
||||||
|
|
||||||
thread_types! {
|
thread_types! {
|
||||||
|
@ -60,21 +57,22 @@ pub fn initialize(x: ThreadState) {
|
||||||
}
|
}
|
||||||
*k.borrow_mut() = Some(x);
|
*k.borrow_mut() = Some(x);
|
||||||
});
|
});
|
||||||
get(); // check the assertion below
|
}
|
||||||
|
|
||||||
|
/// Initializes the current thread as a layout worker thread.
|
||||||
|
pub fn initialize_layout_worker_thread() {
|
||||||
|
initialize(LAYOUT | IN_WORKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the current thread state.
|
/// Gets the current thread state.
|
||||||
pub fn get() -> ThreadState {
|
pub fn get() -> ThreadState {
|
||||||
let state = STATE.with(|ref k| {
|
let state = STATE.with(|ref k| {
|
||||||
match *k.borrow() {
|
match *k.borrow() {
|
||||||
// This is one of the layout threads, that use rayon.
|
None => ThreadState::empty(), // Unknown thread.
|
||||||
None => LAYOUT | IN_WORKER,
|
|
||||||
Some(s) => s,
|
Some(s) => s,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Exactly one of the thread type flags should be set.
|
|
||||||
debug_assert_eq!(1, TYPES.iter().filter(|&&ty| state.contains(ty)).count());
|
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue