diff --git a/Cargo.lock b/Cargo.lock index 7f2a649894e..8561d429649 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -906,6 +906,7 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.18.0", "servo_url 0.0.1", "style 0.0.1", diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index 4ecfe1df520..916680dad39 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -14,7 +14,6 @@ use media_queries::Device; use num_cpus; use parking_lot::RwLock; use properties::ComputedValues; -use rayon; use std::cmp; use std::collections::HashMap; use std::env; @@ -48,13 +47,6 @@ pub struct PerDocumentStyleDataImpl { /// Unused. Will go away when we actually implement transitions and /// animations properly. pub expired_animations: Arc>>>, - - /// The worker thread pool. - /// FIXME(bholley): This shouldn't be per-document. - pub work_queue: Option, - - /// The number of threads of the work queue. - pub num_threads: usize, } /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics @@ -86,14 +78,6 @@ impl PerDocumentStyleData { new_animations_receiver: new_anims_receiver, running_animations: Arc::new(RwLock::new(HashMap::new())), expired_animations: Arc::new(RwLock::new(HashMap::new())), - work_queue: if *NUM_THREADS <= 1 { - None - } else { - let configuration = - rayon::Configuration::new().set_num_threads(*NUM_THREADS); - rayon::ThreadPool::new(configuration).ok() - }, - num_threads: *NUM_THREADS, })) } @@ -141,9 +125,3 @@ unsafe impl HasFFI for PerDocumentStyleData { } unsafe impl HasSimpleFFI for PerDocumentStyleData {} unsafe impl HasBoxFFI for PerDocumentStyleData {} - -impl Drop for PerDocumentStyleDataImpl { - fn drop(&mut self) { - let _ = self.work_queue.take(); - } -} diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 9d54213caec..072d500e8a9 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -23,6 +23,7 @@ libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} num_cpus = "1.1.0" parking_lot = "0.3" +rayon = "0.6" selectors = {path = "../../components/selectors"} servo_url = {path = "../../components/url"} style = {path = "../../components/style", features = ["gecko"]} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 54aac9b4694..711c19a738f 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -9,6 +9,7 @@ use cssparser::ToCss as ParserToCss; use env_logger::LogBuilder; use euclid::Size2D; use parking_lot::RwLock; +use rayon; use selectors::Element; use servo_url::ServoUrl; use std::borrow::Cow; @@ -90,6 +91,20 @@ use stylesheet_loader::StylesheetLoader; * depend on but good enough for our purposes. */ +lazy_static! { + static ref STYLE_THREAD_POOL: Option = { + let num_threads = *NUM_THREADS; + if num_threads <= 1 { + return None; + } + + let configuration = + rayon::Configuration::new().set_num_threads(num_threads); + let pool = rayon::ThreadPool::new(configuration).ok(); + pool + }; +} + #[no_mangle] pub extern "C" fn Servo_Initialize() -> () { // Initialize logging. @@ -148,7 +163,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed, } } - let mut per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); + let per_doc_data = PerDocumentStyleData::from_ffi(raw_data).borrow(); let token = RecalcStyleOnly::pre_traverse(element, &per_doc_data.stylist, unstyled_children_only); if !token.should_traverse() { @@ -159,7 +174,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed, debug!("{:?}", ShowSubtreeData(element.as_node())); let shared_style_context = create_shared_context(&per_doc_data); - let traversal_driver = if per_doc_data.num_threads == 1 || per_doc_data.work_queue.is_none() { + let traversal_driver = if STYLE_THREAD_POOL.is_none() { TraversalDriver::Sequential } else { TraversalDriver::Parallel @@ -169,7 +184,7 @@ fn traverse_subtree(element: GeckoElement, raw_data: RawServoStyleSetBorrowed, let known_depth = None; if traversal_driver.is_parallel() { parallel::traverse_dom(&traversal, element, known_depth, token, - per_doc_data.work_queue.as_mut().unwrap()); + STYLE_THREAD_POOL.as_ref().unwrap()); } else { sequential::traverse_dom(&traversal, element, token); } diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index ff5d4c0e4f4..9363150acf3 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -9,9 +9,11 @@ extern crate atomic_refcell; extern crate cssparser; extern crate env_logger; extern crate euclid; +#[macro_use] extern crate lazy_static; extern crate libc; #[macro_use] extern crate log; extern crate parking_lot; +extern crate rayon; extern crate selectors; extern crate servo_url; extern crate style;