[netwerk] Make nsIncrementalStreamLoader's GetNumBytesRead threadsafe.

This prevents a potential race and simplifies the code a bit by keeping the
bytes read separate instead of using mData, which is modified from another
thread from OnDataAvailable.
Relaxed atomics are fine for these, since they don't guard any memory.
This commit is contained in:
Moonchild 2020-10-23 08:10:01 +00:00 committed by roytam1
commit efa2f805fe
4 changed files with 14 additions and 10 deletions

View file

@ -54,7 +54,7 @@ NS_IMPL_ISUPPORTS(nsStreamLoader, nsIStreamLoader,
NS_IMETHODIMP
nsStreamLoader::GetNumBytesRead(uint32_t* aNumBytes)
{
*aNumBytes = mData.length();
*aNumBytes = mBytesRead;
return NS_OK;
}
@ -150,7 +150,10 @@ nsStreamLoader::OnDataAvailable(nsIRequest* request, nsISupports *ctxt,
uint64_t sourceOffset, uint32_t count)
{
uint32_t countRead;
return inStr->ReadSegments(WriteSegmentFun, this, count, &countRead);
nsresult rv = inStr->ReadSegments(WriteSegmentFun, this, count, &countRead);
NS_ENSURE_SUCCESS(rv, rv);
mBytesRead += countRead;
return NS_OK;
}
void