Move shared lock acquires up the call stack. (Or is it down?)

This commit is contained in:
Simon Sapin 2017-03-16 23:08:10 +01:00
parent c5a7294e05
commit d18b1280f2
5 changed files with 46 additions and 27 deletions

View file

@ -731,7 +731,8 @@ impl LayoutThread {
// GWTODO: Need to handle unloading web fonts.
let rw_data = possibly_locked_rw_data.lock();
if stylesheet.is_effective_for_device(&rw_data.stylist.device) {
let guard = stylesheet.shared_lock.read();
if stylesheet.is_effective_for_device(&rw_data.stylist.device, &guard) {
add_font_face_rules(&*stylesheet,
&rw_data.stylist.device,
&self.font_cache_thread,
@ -1057,9 +1058,11 @@ impl LayoutThread {
}
// If the entire flow tree is invalid, then it will be reflowed anyhow.
let needs_dirtying = Arc::get_mut(&mut rw_data.stylist).unwrap().update(&data.document_stylesheets,
Some(&*UA_STYLESHEETS),
data.stylesheets_changed);
let needs_dirtying = Arc::get_mut(&mut rw_data.stylist).unwrap().update(
&data.document_stylesheets,
&style_guard,
Some(&*UA_STYLESHEETS),
data.stylesheets_changed);
let needs_reflow = viewport_size_changed && !needs_dirtying;
if needs_dirtying {
if let Some(mut d) = element.mutate_data() {

View file

@ -13,6 +13,7 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::Device;
use parking_lot::RwLock;
use properties::ComputedValues;
use shared_lock::SharedRwLockReadGuard;
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender, channel};
@ -83,20 +84,20 @@ impl PerDocumentStyleDataImpl {
/// Reset the device state because it may have changed.
///
/// Implies also a stylesheet flush.
pub fn reset_device(&mut self) {
pub fn reset_device(&mut self, guard: &SharedRwLockReadGuard) {
{
let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
Arc::get_mut(&mut stylist.device).unwrap().reset();
}
self.stylesheets_changed = true;
self.flush_stylesheets();
self.flush_stylesheets(guard);
}
/// Recreate the style data if the stylesheets have changed.
pub fn flush_stylesheets(&mut self) {
pub fn flush_stylesheets(&mut self, guard: &SharedRwLockReadGuard) {
if self.stylesheets_changed {
let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
stylist.update(&self.stylesheets, None, true);
stylist.update(&self.stylesheets, guard, None, true);
self.stylesheets_changed = false;
}
}

View file

@ -647,9 +647,8 @@ impl Stylesheet {
/// on the associated MediaList.
///
/// Always true if no associated MediaList exists.
pub fn is_effective_for_device(&self, device: &Device) -> bool {
let guard = self.shared_lock.read(); // FIXME: have the caller pass this?
self.media.read_with(&guard).evaluate(device)
pub fn is_effective_for_device(&self, device: &Device, guard: &SharedRwLockReadGuard) -> bool {
self.media.read_with(guard).evaluate(device)
}
/// Return an iterator over the effective rules within the style-sheet, as

View file

@ -28,7 +28,7 @@ use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONA
use selectors::matching::{ElementSelectorFlags, StyleRelations, matches_complex_selector};
use selectors::parser::{Selector, SimpleSelector, LocalName as LocalNameSelector, ComplexSelector};
use selectors::parser::SelectorMethods;
#[cfg(feature = "servo")] use shared_lock::SharedRwLockReadGuard;
use shared_lock::SharedRwLockReadGuard;
use sink::Push;
use smallvec::VecLike;
use std::borrow::Borrow;
@ -159,6 +159,7 @@ impl Stylist {
/// device is dirty, which means we need to re-evaluate media queries.
pub fn update(&mut self,
doc_stylesheets: &[Arc<Stylesheet>],
doc_guard: &SharedRwLockReadGuard,
ua_stylesheets: Option<&UserAgentStylesheets>,
stylesheets_changed: bool) -> bool {
if !(self.is_device_dirty || stylesheets_changed) {
@ -193,17 +194,18 @@ impl Stylist {
self.non_common_style_affecting_attributes_selectors.clear();
if let Some(ua_stylesheets) = ua_stylesheets {
let ua_guard = ua_stylesheets.shared_lock.read();
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.add_stylesheet(&stylesheet);
self.add_stylesheet(&stylesheet, &ua_guard);
}
if self.quirks_mode {
self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet);
self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet, &ua_guard);
}
}
for ref stylesheet in doc_stylesheets.iter() {
self.add_stylesheet(stylesheet);
self.add_stylesheet(stylesheet, doc_guard);
}
debug!("Stylist stats:");
@ -227,8 +229,8 @@ impl Stylist {
true
}
fn add_stylesheet(&mut self, stylesheet: &Stylesheet) {
if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device) {
fn add_stylesheet(&mut self, stylesheet: &Stylesheet, guard: &SharedRwLockReadGuard) {
if stylesheet.disabled() || !stylesheet.is_effective_for_device(&self.device, guard) {
return;
}
@ -271,7 +273,7 @@ impl Stylist {
}
CssRule::Import(ref import) => {
let import = import.read();
self.add_stylesheet(&import.stylesheet)
self.add_stylesheet(&import.stylesheet, guard)
}
CssRule::Keyframes(ref keyframes_rule) => {
let keyframes_rule = keyframes_rule.read();