diff options
Diffstat (limited to 'lib/sanitizer_common/sanitizer_quarantine.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_quarantine.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/sanitizer_common/sanitizer_quarantine.h b/lib/sanitizer_common/sanitizer_quarantine.h index b21ab23a7..db4eb7450 100644 --- a/lib/sanitizer_common/sanitizer_quarantine.h +++ b/lib/sanitizer_common/sanitizer_quarantine.h @@ -26,13 +26,15 @@ namespace __sanitizer { template<typename Node> class QuarantineCache; struct QuarantineBatch { - static const uptr kSize = 1024; + static const uptr kSize = 1021; QuarantineBatch *next; uptr size; uptr count; void *batch[kSize]; }; +COMPILER_CHECK(sizeof(QuarantineBatch) <= (1 << 13)); // 8Kb. + // The callback interface is: // void Callback::Recycle(Node *ptr); // void *cb.Allocate(uptr size); @@ -123,8 +125,10 @@ class QuarantineCache { } void Enqueue(Callback cb, void *ptr, uptr size) { - if (list_.empty() || list_.back()->count == QuarantineBatch::kSize) + if (list_.empty() || list_.back()->count == QuarantineBatch::kSize) { AllocBatch(cb); + size += sizeof(QuarantineBatch); // Count the batch in Quarantine size. + } QuarantineBatch *b = list_.back(); b->batch[b->count++] = ptr; b->size += size; @@ -147,9 +151,7 @@ class QuarantineCache { return 0; QuarantineBatch *b = list_.front(); list_.pop_front(); - // FIXME: should probably add SizeSub method? - // See https://code.google.com/p/thread-sanitizer/issues/detail?id=20 - SizeAdd(0 - b->size); + SizeSub(b->size); return b; } @@ -160,6 +162,9 @@ class QuarantineCache { void SizeAdd(uptr add) { atomic_store(&size_, Size() + add, memory_order_relaxed); } + void SizeSub(uptr sub) { + atomic_store(&size_, Size() - sub, memory_order_relaxed); + } NOINLINE QuarantineBatch* AllocBatch(Callback cb) { QuarantineBatch *b = (QuarantineBatch *)cb.Allocate(sizeof(*b)); |