diff --git a/parity-util-mem/Cargo.toml b/parity-util-mem/Cargo.toml index 8fe85da10..a89122723 100644 --- a/parity-util-mem/Cargo.toml +++ b/parity-util-mem/Cargo.toml @@ -33,7 +33,7 @@ optional = true [features] default = ["std", "ethereum-impls"] -std = [] +std = ["parking_lot"] # use dlmalloc as global allocator dlmalloc-global = ["dlmalloc", "estimate-heapsize"] # use wee_alloc as global allocator @@ -43,6 +43,6 @@ jemalloc-global = ["jemallocator"] # use mimalloc as global allocator mimalloc-global = ["mimallocator", "mimalloc-sys"] # implement additional types -ethereum-impls = ["ethereum-types", "parking_lot", "smallvec"] +ethereum-impls = ["ethereum-types", "smallvec"] # Full estimate: no call to allocator estimate-heapsize = [] diff --git a/parity-util-mem/src/impls.rs b/parity-util-mem/src/impls.rs index ad1962d7f..322375873 100644 --- a/parity-util-mem/src/impls.rs +++ b/parity-util-mem/src/impls.rs @@ -17,12 +17,10 @@ //! Implementation of `MallocSize` for common types : //! - ethereum types uint and fixed hash. //! - smallvec arrays of sizes 32, 36 -//! - parking_lot mutex structures use super::{MallocSizeOf, MallocSizeOfOps}; use ethereum_types::{Bloom, H128, H160, H256, H264, H32, H512, H520, H64, U128, U256, U512, U64}; -use parking_lot::{Mutex, RwLock}; use smallvec::SmallVec; #[cfg(not(feature = "std"))] @@ -54,18 +52,6 @@ macro_rules! impl_smallvec { impl_smallvec!(32); // kvdb uses this impl_smallvec!(36); // trie-db uses this -impl MallocSizeOf for Mutex { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - (*self.lock()).size_of(ops) - } -} - -impl MallocSizeOf for RwLock { - fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - self.read().size_of(ops) - } -} - #[cfg(test)] mod tests { use crate::{allocators::new_malloc_size_ops, MallocSizeOf, MallocSizeOfOps}; diff --git a/parity-util-mem/src/malloc_size.rs b/parity-util-mem/src/malloc_size.rs index a3018af1f..a748eec82 100644 --- a/parity-util-mem/src/malloc_size.rs +++ b/parity-util-mem/src/malloc_size.rs @@ -43,7 +43,8 @@ //! measured as well as the thing it points to. E.g. //! ` as MallocSizeOf>::size_of(field, ops)`. -// This file is patched at commit 5bdea7dc1c80790a852a3fb03edfb2b8fbd403dc DO NOT EDIT. +//! This is an extended (for own internal needs) version of the Servo internal malloc_size crate. +//! We should occasionally track the upstream changes/fixes and reintroduce them here, be they applicable. #[cfg(not(feature = "std"))] use alloc::vec::Vec; @@ -539,10 +540,33 @@ impl MallocConditionalSizeOf for Arc { /// If a mutex is stored inside of an Arc value as a member of a data type that is being measured, /// the Arc will not be automatically measured so there is no risk of overcounting the mutex's /// contents. +/// +/// The same reasoning applies to RwLock. #[cfg(feature = "std")] impl MallocSizeOf for std::sync::Mutex { fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { - (*self.lock().unwrap()).size_of(ops) + self.lock().unwrap().size_of(ops) + } +} + +#[cfg(feature = "std")] +impl MallocSizeOf for parking_lot::Mutex { + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.lock().size_of(ops) + } +} + +#[cfg(feature = "std")] +impl MallocSizeOf for std::sync::RwLock { + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.read().unwrap().size_of(ops) + } +} + +#[cfg(feature = "std")] +impl MallocSizeOf for parking_lot::RwLock { + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + self.read().size_of(ops) } }