style: Shutdown Servo's thread-pool in leak-checking builds, leak the atom table elsewhere.

Differential Revision: https://phabricator.services.mozilla.com/D44217
This commit is contained in:
Emilio Cobos Álvarez 2019-09-09 22:39:46 +00:00
parent d54d1bcb17
commit 9eaadc6860
4 changed files with 70 additions and 18 deletions

View file

@ -13,13 +13,20 @@ use owning_ref::OwningHandle;
use selectors::bloom::BloomFilter;
use servo_arc::Arc;
use smallvec::SmallVec;
use std::mem::ManuallyDrop;
thread_local! {
/// Bloom filters are large allocations, so we store them in thread-local storage
/// such that they can be reused across style traversals. StyleBloom is responsible
/// for ensuring that the bloom filter is zeroed when it is dropped.
static BLOOM_KEY: Arc<AtomicRefCell<BloomFilter>> =
Arc::new_leaked(AtomicRefCell::new(BloomFilter::new()));
///
/// We intentionally leak this from TLS because we don't have the guarantee
/// of TLS destructors to run in worker threads.
///
/// We could change this once https://github.com/rayon-rs/rayon/issues/688
/// is fixed, hopefully.
static BLOOM_KEY: ManuallyDrop<Arc<AtomicRefCell<BloomFilter>>> =
ManuallyDrop::new(Arc::new_leaked(Default::default()));
}
/// A struct that allows us to fast-reject deep descendant selectors avoiding
@ -128,7 +135,7 @@ impl<E: TElement> StyleBloom<E> {
// See https://github.com/servo/servo/pull/18420#issuecomment-328769322
#[inline(never)]
pub fn new() -> Self {
let bloom_arc = BLOOM_KEY.with(|b| b.clone());
let bloom_arc = BLOOM_KEY.with(|b| Arc::clone(&*b));
let filter =
OwningHandle::new_with_fn(bloom_arc, |x| unsafe { x.as_ref() }.unwrap().borrow_mut());
debug_assert!(
@ -136,7 +143,7 @@ impl<E: TElement> StyleBloom<E> {
"Forgot to zero the bloom filter last time"
);
StyleBloom {
filter: filter,
filter,
elements: Default::default(),
pushed_hashes: Default::default(),
}