geckolib: move NUM_THREADS from style to geckolib

This change eliminates some gecko-only configuration in the style
component and moves NUM_THREADS closer to its only uses.
This commit is contained in:
Nathan Froyd 2017-02-22 11:22:16 -05:00
parent 3e81f8431e
commit fafcdda16a
6 changed files with 15 additions and 21 deletions

View file

@ -8,11 +8,13 @@ use cssparser::Parser;
use cssparser::ToCss as ParserToCss;
use env_logger::LogBuilder;
use euclid::Size2D;
use num_cpus;
use parking_lot::RwLock;
use rayon;
use selectors::Element;
use servo_url::ServoUrl;
use std::borrow::Cow;
use std::cmp;
use std::env;
use std::fmt::Write;
use std::mem;
@ -24,7 +26,7 @@ use style::context::{ThreadLocalStyleContext, ThreadLocalStyleContextCreationInf
use style::data::{ElementData, ElementStyles, RestyleData};
use style::dom::{ShowSubtreeData, TElement, TNode};
use style::error_reporting::StdoutErrorReporter;
use style::gecko::data::{NUM_THREADS, PerDocumentStyleData, PerDocumentStyleDataImpl};
use style::gecko::data::{PerDocumentStyleData, PerDocumentStyleDataImpl};
use style::gecko::restyle_damage::GeckoRestyleDamage;
use style::gecko::selector_parser::{SelectorImpl, PseudoElement};
use style::gecko::traversal::RecalcStyleOnly;
@ -91,6 +93,16 @@ use stylesheet_loader::StylesheetLoader;
* depend on but good enough for our purposes.
*/
lazy_static! {
/// The number of layout threads, computed statically.
static ref NUM_THREADS: usize = {
match env::var("STYLO_THREADS").map(|s| s.parse::<usize>().expect("invalid STYLO_THREADS")) {
Ok(num) => num,
_ => cmp::max(num_cpus::get() * 3 / 4, 1),
}
};
}
lazy_static! {
static ref STYLE_THREAD_POOL: Option<rayon::ThreadPool> = {
let num_threads = *NUM_THREADS;

View file

@ -12,6 +12,7 @@ extern crate euclid;
#[macro_use] extern crate lazy_static;
extern crate libc;
#[macro_use] extern crate log;
extern crate num_cpus;
extern crate parking_lot;
extern crate rayon;
extern crate selectors;