Skip to content

Commit

Permalink
geckolib: move NUM_THREADS from style to geckolib
Browse files Browse the repository at this point in the history
This change eliminates some gecko-only configuration in the style
component and moves NUM_THREADS closer to its only uses.
  • Loading branch information
froydnj committed Feb 22, 2017
1 parent 3e81f84 commit fafcdda
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions components/style/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ path = "lib.rs"
doctest = false

[features]
gecko = ["nsstring_vendor", "num_cpus", "rayon/unstable"]
gecko = ["nsstring_vendor", "rayon/unstable"]
use_bindgen = ["bindgen", "regex"]
servo = ["serde/unstable", "serde", "serde_derive", "heapsize_derive",
"style_traits/servo", "servo_atoms", "html5ever-atoms",
Expand Down Expand Up @@ -57,10 +57,6 @@ servo_url = {path = "../url"}
time = "0.1"
unicode-segmentation = "1.0"

[dependencies.num_cpus]
optional = true
version = "1.0"

[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2"

Expand Down
13 changes: 0 additions & 13 deletions components/style/gecko/data.rs
Expand Up @@ -11,12 +11,9 @@ use gecko_bindings::bindings::RawServoStyleSet;
use gecko_bindings::structs::RawGeckoPresContextOwned;
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::Device;
use num_cpus;
use parking_lot::RwLock;
use properties::ComputedValues;
use std::cmp;
use std::collections::HashMap;
use std::env;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
use stylesheets::Stylesheet;
Expand Down Expand Up @@ -53,16 +50,6 @@ pub struct PerDocumentStyleDataImpl {
/// and unexpected races while trying to mutate it.
pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);

lazy_static! {
/// The number of layout threads, computed statically.
pub 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),
}
};
}

impl PerDocumentStyleData {
/// Create a dummy `PerDocumentStyleData`.
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
Expand Down
1 change: 0 additions & 1 deletion components/style/lib.rs
Expand Up @@ -61,7 +61,6 @@ extern crate matches;
#[cfg(feature = "gecko")] extern crate nsstring_vendor as nsstring;
extern crate num_integer;
extern crate num_traits;
#[cfg(feature = "gecko")] extern crate num_cpus;
extern crate ordered_float;
extern crate owning_ref;
extern crate parking_lot;
Expand Down
14 changes: 13 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ports/geckolib/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit fafcdda

Please sign in to comment.