[sanitizer] Remove SpinMutexLock from stat function

Mapped size is more appropriate for most users.

Depends on D111605.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D111607
This commit is contained in:
Vitaly Buka 2021-10-09 23:27:39 -07:00
parent b4b9f9b4b3
commit 884d290427
2 changed files with 7 additions and 9 deletions

View File

@ -24,11 +24,7 @@ template <typename T>
class PersistentAllocator {
public:
T *alloc(uptr count = 1);
uptr allocated() const {
SpinMutexLock l(&mtx);
return atomic_load_relaxed(&mapped_size) +
atomic_load_relaxed(&region_pos) - atomic_load_relaxed(&region_end);
}
uptr allocated() const { return atomic_load_relaxed(&mapped_size); }
private:
T *tryAlloc(uptr count);

View File

@ -81,10 +81,12 @@ TEST(SanitizerCommon, ChainedOriginDepotStats) {
EXPECT_EQ(stats2.n_uniq_ids, stats1.n_uniq_ids);
EXPECT_EQ(stats2.allocated, stats1.allocated);
EXPECT_TRUE(chainedOriginDepot.Put(35, 36, &new_id));
StackDepotStats stats3 = chainedOriginDepot.GetStats();
EXPECT_EQ(stats3.n_uniq_ids, stats2.n_uniq_ids + 1);
EXPECT_GT(stats3.allocated, stats2.allocated);
for (int i = 0; i < 100000; ++i) {
ASSERT_TRUE(chainedOriginDepot.Put(35, i, &new_id));
StackDepotStats stats3 = chainedOriginDepot.GetStats();
ASSERT_EQ(stats3.n_uniq_ids, stats2.n_uniq_ids + 1 + i);
}
EXPECT_GT(chainedOriginDepot.GetStats().allocated, stats2.allocated);
}
} // namespace __sanitizer