From 90e9bbbadc6b02596a1cd9a6fdaa9e52cfb26745 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 19 Sep 2017 12:13:34 -0700 Subject: [PATCH] Explicitly register rayon threads, rather than assuming that as the default. MozReview-Commit-ID: E4kUyy8HjmV --- components/layout_thread/lib.rs | 3 ++- components/style/gecko/global_style_data.rs | 2 ++ components/style/thread_state.rs | 14 ++++++-------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index c9a80b7ddd8..64ef126b79e 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -461,7 +461,8 @@ impl LayoutThread { ScaleFactor::new(opts::get().device_pixels_per_px.unwrap_or(1.0))); 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 { Some(rayon::ThreadPool::new(configuration).expect("ThreadPool creation failed")) } else { diff --git a/components/style/gecko/global_style_data.rs b/components/style/gecko/global_style_data.rs index a4812b95a4f..4a6dcc21805 100644 --- a/components/style/gecko/global_style_data.rs +++ b/components/style/gecko/global_style_data.rs @@ -15,6 +15,7 @@ use shared_lock::SharedRwLock; use std::cmp; use std::env; use std::ffi::CString; +use thread_state; /// Global style data pub struct GlobalStyleData { @@ -39,6 +40,7 @@ fn thread_name(index: usize) -> String { } fn thread_startup(index: usize) { + thread_state::initialize_layout_worker_thread(); unsafe { Gecko_SetJemallocThreadLocalArena(true); } diff --git a/components/style/thread_state.rs b/components/style/thread_state.rs index 3c06666a057..894cdb4a813 100644 --- a/components/style/thread_state.rs +++ b/components/style/thread_state.rs @@ -40,9 +40,6 @@ macro_rules! thread_types ( ( $( $fun:ident = $flag:ident ; )* ) => ( } )* } - - static TYPES: &'static [ThreadState] = - &[ $( $flag ),* ]; )); thread_types! { @@ -60,21 +57,22 @@ pub fn initialize(x: ThreadState) { } *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. pub fn get() -> ThreadState { let state = STATE.with(|ref k| { match *k.borrow() { - // This is one of the layout threads, that use rayon. - None => LAYOUT | IN_WORKER, + None => ThreadState::empty(), // Unknown thread. 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 }