mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
style: Simplify code for keeping alive shared memory until all sheets go away.
The existing code wasn't sound, as CSSOM objects also needed to go away before the shared memory goes away (as they keep references to them). This is sound assuming no presence of reference cycles introduced by CSSOM. We may want to live with this and rely on chrome code not writing cycles like this with UA stylesheet DOM objects. We could explicitly drop all potentially-static objects... That seems pretty error prone though. Or we could also just leak the shared memory buffer, is there any reason why we may not want to do that? Differential Revision: https://phabricator.services.mozilla.com/D51870
This commit is contained in:
parent
9c1dd4b3ea
commit
cceb0bcb73
2 changed files with 13 additions and 4 deletions
|
@ -485,6 +485,14 @@ impl<T: ?Sized> Arc<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Whether or not the `Arc` is a static reference.
|
||||
#[inline]
|
||||
pub fn is_static(&self) -> bool {
|
||||
// Using a relaxed ordering to check for STATIC_REFCOUNT is safe, since
|
||||
// `count` never changes between STATIC_REFCOUNT and other values.
|
||||
self.inner().count.load(Relaxed) == STATIC_REFCOUNT
|
||||
}
|
||||
|
||||
/// Whether or not the `Arc` is uniquely owned (is the refcount 1?) and not
|
||||
/// a static reference.
|
||||
#[inline]
|
||||
|
@ -501,10 +509,7 @@ impl<T: ?Sized> Drop for Arc<T> {
|
|||
fn drop(&mut self) {
|
||||
// NOTE(emilio): If you change anything here, make sure that the
|
||||
// implementation in layout/style/ServoStyleConstsInlines.h matches!
|
||||
//
|
||||
// Using a relaxed ordering to check for STATIC_REFCOUNT is safe, since
|
||||
// `count` never changes between STATIC_REFCOUNT and other values.
|
||||
if self.inner().count.load(Relaxed) == STATIC_REFCOUNT {
|
||||
if self.is_static() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -124,6 +124,7 @@ impl StylesheetContents {
|
|||
url_data: UrlExtraData,
|
||||
quirks_mode: QuirksMode,
|
||||
) -> Self {
|
||||
debug_assert!(rules.is_static());
|
||||
Self {
|
||||
rules,
|
||||
origin,
|
||||
|
@ -144,6 +145,9 @@ impl StylesheetContents {
|
|||
/// Measure heap usage.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
|
||||
if self.rules.is_static() {
|
||||
return 0;
|
||||
}
|
||||
// Measurement of other fields may be added later.
|
||||
self.rules.unconditional_shallow_size_of(ops) +
|
||||
self.rules.read_with(guard).size_of(guard, ops)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue