Bug 1062661 - Part 1: Fix ResourceQueue::Evict so that it tries to remove enough data to get us under the threshold. r=kinetik

This commit is contained in:
Matt Woodrow 2014-11-04 11:16:31 +13:00
parent a5e21ac675
commit 35792c7281

View File

@ -102,20 +102,22 @@ public:
Push(new ResourceItem(aData, aLength));
}
// Evict data in queue if the total queue size is greater than
// aThreshold past the offset. Returns amount evicted.
uint32_t Evict(uint64_t aOffset, uint32_t aThreshold) {
// Tries to evict at least aSizeToEvict from the queue up until
// aOffset. Returns amount evicted.
uint32_t Evict(uint64_t aOffset, uint32_t aSizeToEvict) {
uint32_t evicted = 0;
while (GetLength() - mOffset > aThreshold) {
ResourceItem* item = ResourceAt(0);
while (ResourceItem* item = ResourceAt(0)) {
if (item->mData.Length() + mOffset > aOffset) {
break;
}
mOffset += item->mData.Length();
evicted += item->mData.Length();
SBR_DEBUGV("ResourceQueue(%p)::Evict(%llu, %u) removed chunk length=%u",
this, aOffset, aThreshold, item->mData.Length());
this, aOffset, aSizeToEvict, item->mData.Length());
delete PopFront();
if (aSizeToEvict && evicted >= aSizeToEvict) {
break;
}
}
return evicted;
}