mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
More lock acquire in callers
This commit is contained in:
parent
d18b1280f2
commit
3ae2ecbec2
6 changed files with 45 additions and 25 deletions
|
@ -658,9 +658,9 @@ impl Stylesheet {
|
|||
/// nested rules will be skipped. Use `rules` if all rules need to be
|
||||
/// examined.
|
||||
#[inline]
|
||||
pub fn effective_rules<F>(&self, device: &Device, mut f: F) where F: FnMut(&CssRule) {
|
||||
let guard = self.shared_lock.read(); // FIXME: have the caller pass this?
|
||||
effective_rules(&self.rules.read().0, device, &guard, &mut f);
|
||||
pub fn effective_rules<F>(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F)
|
||||
where F: FnMut(&CssRule) {
|
||||
effective_rules(&self.rules.read().0, device, guard, &mut f);
|
||||
}
|
||||
|
||||
/// Returns whether the stylesheet has been explicitly disabled through the
|
||||
|
@ -701,8 +701,9 @@ macro_rules! rule_filter {
|
|||
impl Stylesheet {
|
||||
$(
|
||||
#[allow(missing_docs)]
|
||||
pub fn $method<F>(&self, device: &Device, mut f: F) where F: FnMut(&$rule_type) {
|
||||
self.effective_rules(device, |rule| {
|
||||
pub fn $method<F>(&self, device: &Device, guard: &SharedRwLockReadGuard, mut f: F)
|
||||
where F: FnMut(&$rule_type) {
|
||||
self.effective_rules(device, guard, |rule| {
|
||||
if let CssRule::$variant(ref lock) = *rule {
|
||||
let rule = lock.read();
|
||||
f(&rule)
|
||||
|
|
|
@ -167,7 +167,9 @@ impl Stylist {
|
|||
}
|
||||
|
||||
let cascaded_rule = ViewportRule {
|
||||
declarations: viewport::Cascade::from_stylesheets(doc_stylesheets, &self.device).finish(),
|
||||
declarations: viewport::Cascade::from_stylesheets(
|
||||
doc_stylesheets, doc_guard, &self.device
|
||||
).finish(),
|
||||
};
|
||||
|
||||
self.viewport_constraints =
|
||||
|
@ -237,7 +239,7 @@ impl Stylist {
|
|||
// Cheap `Arc` clone so that the closure below can borrow `&mut Stylist`.
|
||||
let device = self.device.clone();
|
||||
|
||||
stylesheet.effective_rules(&device, |rule| {
|
||||
stylesheet.effective_rules(&device, guard, |rule| {
|
||||
match *rule {
|
||||
CssRule::Style(ref style_rule) => {
|
||||
let guard = style_rule.read();
|
||||
|
@ -467,7 +469,7 @@ impl Stylist {
|
|||
pub fn set_device(&mut self, mut device: Device, guard: &SharedRwLockReadGuard,
|
||||
stylesheets: &[Arc<Stylesheet>]) {
|
||||
let cascaded_rule = ViewportRule {
|
||||
declarations: viewport::Cascade::from_stylesheets(stylesheets, &device).finish(),
|
||||
declarations: viewport::Cascade::from_stylesheets(stylesheets, guard, &device).finish(),
|
||||
};
|
||||
|
||||
self.viewport_constraints =
|
||||
|
|
|
@ -15,6 +15,7 @@ use cssparser::ToCss as ParserToCss;
|
|||
use euclid::size::TypedSize2D;
|
||||
use media_queries::Device;
|
||||
use parser::{ParserContext, log_css_error};
|
||||
use shared_lock::SharedRwLockReadGuard;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
|
@ -555,13 +556,14 @@ impl Cascade {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_stylesheets<'a, I>(stylesheets: I, device: &Device) -> Self
|
||||
pub fn from_stylesheets<'a, I>(stylesheets: I, guard: &SharedRwLockReadGuard,
|
||||
device: &Device) -> Self
|
||||
where I: IntoIterator,
|
||||
I::Item: AsRef<Stylesheet>,
|
||||
{
|
||||
let mut cascade = Self::new();
|
||||
for stylesheet in stylesheets {
|
||||
stylesheet.as_ref().effective_viewport_rules(device, |rule| {
|
||||
stylesheet.as_ref().effective_viewport_rules(device, guard, |rule| {
|
||||
for declaration in &rule.declarations {
|
||||
cascade.add(Cow::Borrowed(declaration))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue