Bug 1618868 Part 3: Fix failure test race in CanvasEventRingBuffer::ReturnRead. r=jrmuizel

This also adds checks for the other side closing during the ReturnRead and
ReturnWrite loops.

Depends on D70336

Differential Revision: https://phabricator.services.mozilla.com/D70337

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bob Owen 2020-04-14 17:53:15 +00:00
parent 00d118c48c
commit c640645fb9

View File

@ -435,6 +435,8 @@ void CanvasEventRingBuffer::ReturnWrite(const char* aData, size_t aSize) {
bufRemaining = kStreamSize - bufPos;
aData += availableToWrite;
aSize -= availableToWrite;
} else if (mReaderServices->WriterClosed()) {
return;
}
availableToWrite = std::min(
@ -455,7 +457,9 @@ void CanvasEventRingBuffer::ReturnRead(char* aOut, size_t aSize) {
// nothing. So, wait until something has been written or the reader has
// stopped processing.
while (readCount == mRead->returnCount) {
if (mRead->state != State::Processing) {
// We recheck the count, because the other side can write all the data and
// started waiting in between these two lines.
if (mRead->state != State::Processing && readCount == mRead->returnCount) {
return;
}
}
@ -473,6 +477,8 @@ void CanvasEventRingBuffer::ReturnRead(char* aOut, size_t aSize) {
bufRemaining = kStreamSize - bufPos;
aOut += availableToRead;
aSize -= availableToRead;
} else if (mWriterServices->ReaderClosed()) {
return;
}
availableToRead = std::min(bufRemaining, (mRead->returnCount - readCount));