diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index eecd26a498a..39cfddd3738 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -23,8 +23,6 @@ use stylist::{ExtraStyleData, Stylist}; #[derive(PartialEq, Eq, Debug)] pub struct GeckoStyleSheet(*const ServoStyleSheet); -unsafe impl Sync for GeckoStyleSheet {} - impl ToMediaListKey for ::gecko::data::GeckoStyleSheet { fn to_media_list_key(&self) -> MediaListKey { use std::mem; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 49e96667885..dc6924c6c5b 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -36,6 +36,7 @@ use servo_arc::{Arc, ArcBorrow}; use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; use smallvec::VecLike; use std::fmt::Debug; +use std::ops; use style_traits::viewport::ViewportConstraints; use stylesheet_set::{StylesheetSet, StylesheetIterator}; #[cfg(feature = "gecko")] @@ -320,6 +321,33 @@ impl DocumentCascadeData { } } +/// A wrapper over a StylesheetSet that can be `Sync`, since it's only used and +/// exposed via mutable methods in the `Stylist`. +#[cfg_attr(feature = "servo", derive(HeapSizeOf))] +struct StylistStylesheetSet(StylesheetSet); +// Read above to see why this is fine. +unsafe impl Sync for StylistStylesheetSet {} + +impl StylistStylesheetSet { + fn new() -> Self { + StylistStylesheetSet(StylesheetSet::new()) + } +} + +impl ops::Deref for StylistStylesheetSet { + type Target = StylesheetSet; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl ops::DerefMut for StylistStylesheetSet { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + /// This structure holds all the selectors and device characteristics /// for a given document. The selectors are converted into `Rule`s /// and sorted into `SelectorMap`s keyed off stylesheet origin and @@ -347,7 +375,7 @@ pub struct Stylist { viewport_constraints: Option, /// The list of stylesheets. - stylesheets: StylesheetSet, + stylesheets: StylistStylesheetSet, /// If true, the quirks-mode stylesheet is applied. #[cfg_attr(feature = "servo", ignore_heap_size_of = "defined in selectors")] @@ -396,7 +424,7 @@ impl Stylist { viewport_constraints: None, device, quirks_mode, - stylesheets: StylesheetSet::new(), + stylesheets: StylistStylesheetSet::new(), cascade_data: Default::default(), rule_tree: RuleTree::new(), num_rebuilds: 0,