File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
compiler-rt/lib/scudo/standalone Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -101,12 +101,22 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
101
101
Stats.add (StatFree, ClassSize);
102
102
}
103
103
104
+ bool isEmpty () const {
105
+ for (uptr I = 0 ; I < NumClasses; ++I)
106
+ if (PerClassArray[I].Count )
107
+ return false ;
108
+ return true ;
109
+ }
110
+
104
111
void drain () {
105
- for (uptr I = 0 ; I < NumClasses; I++) {
112
+ // Drain BatchClassId (0) the last as createBatch can refill it.
113
+ for (uptr I = NumClasses; I;) {
114
+ --I;
106
115
PerClass *C = &PerClassArray[I];
107
116
while (C->Count > 0 )
108
117
drain (C, I);
109
118
}
119
+ DCHECK (isEmpty ());
110
120
}
111
121
112
122
TransferBatch *createBatch (uptr ClassId, void *B) {
Original file line number Diff line number Diff line change @@ -311,6 +311,14 @@ template <class Config> static void testAllocator() {
311
311
EXPECT_NE (Stats.find (" Stats: SizeClassAllocator" ), std::string::npos);
312
312
EXPECT_NE (Stats.find (" Stats: MapAllocator" ), std::string::npos);
313
313
EXPECT_NE (Stats.find (" Stats: Quarantine" ), std::string::npos);
314
+
315
+ bool UnlockRequired;
316
+ auto *TSD = Allocator->getTSDRegistry ()->getTSDAndLock (&UnlockRequired);
317
+ EXPECT_TRUE (!TSD->Cache .isEmpty ());
318
+ TSD->Cache .drain ();
319
+ EXPECT_TRUE (TSD->Cache .isEmpty ());
320
+ if (UnlockRequired)
321
+ TSD->unlock ();
314
322
}
315
323
316
324
// Test that multiple instantiations of the allocator have not messed up the
You can’t perform that action at this time.
0 commit comments