mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Replace RwLock<CssRules> with Locked<CssRules>
This commit is contained in:
parent
b213daaa88
commit
f35b4e27b3
15 changed files with 85 additions and 52 deletions
|
@ -508,7 +508,7 @@ unsafe impl JSTraceable for RwLock<FontFaceRule> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<CssRules> {
|
||||
unsafe impl JSTraceable for StyleLocked<CssRules> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
|
|
@ -10,9 +10,8 @@ use dom::cssmediarule::CSSMediaRule;
|
|||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom::csssupportsrule::CSSSupportsRule;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::shared_lock::{SharedRwLock, Locked};
|
||||
use style::stylesheets::CssRules as StyleCssRules;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -22,7 +21,7 @@ pub struct CSSConditionRule {
|
|||
|
||||
impl CSSConditionRule {
|
||||
pub fn new_inherited(parent_stylesheet: &CSSStyleSheet,
|
||||
rules: Arc<RwLock<StyleCssRules>>) -> CSSConditionRule {
|
||||
rules: Arc<Locked<StyleCssRules>>) -> CSSConditionRule {
|
||||
CSSConditionRule {
|
||||
cssgroupingrule: CSSGroupingRule::new_inherited(parent_stylesheet, rules),
|
||||
}
|
||||
|
|
|
@ -12,22 +12,21 @@ use dom::cssrule::CSSRule;
|
|||
use dom::cssrulelist::{CSSRuleList, RulesSource};
|
||||
use dom::cssstylesheet::CSSStyleSheet;
|
||||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::shared_lock::{SharedRwLock, Locked};
|
||||
use style::stylesheets::CssRules as StyleCssRules;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct CSSGroupingRule {
|
||||
cssrule: CSSRule,
|
||||
#[ignore_heap_size_of = "Arc"]
|
||||
rules: Arc<RwLock<StyleCssRules>>,
|
||||
rules: Arc<Locked<StyleCssRules>>,
|
||||
rulelist: MutNullableJS<CSSRuleList>,
|
||||
}
|
||||
|
||||
impl CSSGroupingRule {
|
||||
pub fn new_inherited(parent_stylesheet: &CSSStyleSheet,
|
||||
rules: Arc<RwLock<StyleCssRules>>) -> CSSGroupingRule {
|
||||
rules: Arc<Locked<StyleCssRules>>) -> CSSGroupingRule {
|
||||
CSSGroupingRule {
|
||||
cssrule: CSSRule::new_inherited(parent_stylesheet),
|
||||
rules: rules,
|
||||
|
|
|
@ -15,6 +15,7 @@ use dom::window::Window;
|
|||
use dom_struct::dom_struct;
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::Locked;
|
||||
use style::stylesheets::{CssRules, KeyframesRule, RulesMutateError};
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -43,7 +44,7 @@ pub struct CSSRuleList {
|
|||
}
|
||||
|
||||
pub enum RulesSource {
|
||||
Rules(Arc<RwLock<CssRules>>),
|
||||
Rules(Arc<Locked<CssRules>>),
|
||||
Keyframes(Arc<RwLock<KeyframesRule>>),
|
||||
}
|
||||
|
||||
|
@ -52,7 +53,8 @@ impl CSSRuleList {
|
|||
pub fn new_inherited(parent_stylesheet: &CSSStyleSheet, rules: RulesSource) -> CSSRuleList {
|
||||
let dom_rules = match rules {
|
||||
RulesSource::Rules(ref rules) => {
|
||||
rules.read().0.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
rules.read_with(&guard).0.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
}
|
||||
RulesSource::Keyframes(ref rules) => {
|
||||
rules.read().keyframes.iter().map(|_| MutNullableJS::new(None)).collect()
|
||||
|
@ -89,7 +91,9 @@ impl CSSRuleList {
|
|||
let index = idx as usize;
|
||||
|
||||
let parent_stylesheet = self.parent_stylesheet.style_stylesheet();
|
||||
let new_rule = css_rules.write().insert_rule(rule, parent_stylesheet, index, nested)?;
|
||||
let mut guard = parent_stylesheet.shared_lock.write();
|
||||
let new_rule = css_rules.write_with(&mut guard)
|
||||
.insert_rule(rule, parent_stylesheet, index, nested)?;
|
||||
|
||||
let parent_stylesheet = &*self.parent_stylesheet;
|
||||
let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);
|
||||
|
@ -103,7 +107,8 @@ impl CSSRuleList {
|
|||
|
||||
match self.rules {
|
||||
RulesSource::Rules(ref css_rules) => {
|
||||
css_rules.write().remove_rule(index)?;
|
||||
let mut guard = self.parent_stylesheet.shared_lock().write();
|
||||
css_rules.write_with(&mut guard).remove_rule(index)?;
|
||||
let mut dom_rules = self.dom_rules.borrow_mut();
|
||||
dom_rules[index].get().map(|r| r.detach());
|
||||
dom_rules.remove(index);
|
||||
|
@ -133,9 +138,10 @@ impl CSSRuleList {
|
|||
let parent_stylesheet = &self.parent_stylesheet;
|
||||
match self.rules {
|
||||
RulesSource::Rules(ref rules) => {
|
||||
let guard = parent_stylesheet.shared_lock().read();
|
||||
CSSRule::new_specific(self.global().as_window(),
|
||||
parent_stylesheet,
|
||||
rules.read().0[idx as usize].clone())
|
||||
rules.read_with(&guard).0[idx as usize].clone())
|
||||
}
|
||||
RulesSource::Keyframes(ref rules) => {
|
||||
Root::upcast(CSSKeyframeRule::new(self.global().as_window(),
|
||||
|
|
|
@ -16,6 +16,7 @@ use dom::window::Window;
|
|||
use dom_struct::dom_struct;
|
||||
use std::cell::Cell;
|
||||
use std::sync::Arc;
|
||||
use style::shared_lock::SharedRwLock;
|
||||
use style::stylesheets::Stylesheet as StyleStyleSheet;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -72,6 +73,10 @@ impl CSSStyleSheet {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn shared_lock(&self) -> &SharedRwLock {
|
||||
&self.style_stylesheet.shared_lock
|
||||
}
|
||||
|
||||
pub fn style_stylesheet(&self) -> &StyleStyleSheet {
|
||||
&self.style_stylesheet
|
||||
}
|
||||
|
|
|
@ -101,8 +101,9 @@ impl HTMLMetaElement {
|
|||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||
let document = self.upcast::<Node>().owner_doc();
|
||||
let shared_lock = document.style_shared_lock();
|
||||
let rule = CssRule::Viewport(Arc::new(RwLock::new(translated_rule)));
|
||||
*self.stylesheet.borrow_mut() = Some(Arc::new(Stylesheet {
|
||||
rules: CssRules::new(vec![CssRule::Viewport(Arc::new(RwLock::new(translated_rule)))]),
|
||||
rules: CssRules::new(vec![rule], shared_lock),
|
||||
origin: Origin::Author,
|
||||
shared_lock: shared_lock.clone(),
|
||||
base_url: window_from_node(self).get_url(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue