Bug 1416084. P1 - reapply bug 1412737 P4: wake up readers only when we have blocks committed to the cache. r=bechen,gerald

Per bug 1412737 P2 changes, a reader will always read data from the cache or
from the last block in the memory. NotifyDataReceived() will be slightly more
efficient if we don't wake up readers unnecessarily when there are no new blocks
committed to the cache.

MozReview-Commit-ID: Afcy5OOeIk3

--HG--
extra : rebase_source : 64916432081d23234e4cc923c343a9724d6c77db
This commit is contained in:
JW Wang 2018-01-15 10:09:02 +08:00
Родитель 6bd1c596fd
Коммит 0ac7a8be1f
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -2087,6 +2087,9 @@ MediaCacheStream::NotifyDataReceived(uint32_t aLoadID,
mDownloadStatistics.AddBytes(aCount);
// True if we commit any blocks to the cache.
bool cacheUpdated = false;
auto source = MakeSpan<const uint8_t>(aData, aCount);
// We process the data one block (or part of a block) at a time
@ -2115,6 +2118,7 @@ MediaCacheStream::NotifyDataReceived(uint32_t aLoadID,
source.First(remaining));
source = source.From(remaining);
mChannelOffset += remaining;
cacheUpdated = true;
} else {
// The buffer to be filled in the partial block.
auto buf = MakeSpan<uint8_t>(mPartialBlockBuffer.get() + partial.Length(),
@ -2134,10 +2138,12 @@ MediaCacheStream::NotifyDataReceived(uint32_t aLoadID,
stream->mClient->CacheClientNotifyDataReceived();
}
// Notify in case there's a waiting reader
// XXX it would be fairly easy to optimize things a lot more to
// avoid waking up reader threads unnecessarily
lock.NotifyAll();
if (cacheUpdated) {
// Wake up the reader who is waiting for the committed blocks.
lock.NotifyAll();
}
}
void