diff options
author | Moonchild <moonchild@palemoon.org> | 2020-10-23 08:10:01 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2020-10-24 10:38:50 +0000 |
commit | f07d60c09fc0fea2bc614146d13346bc7473b87e (patch) | |
tree | d823fc78c97a0f611ee7ad492c58d84858004461 /netwerk/base/nsStreamLoader.cpp | |
parent | d7a05ea9e50f7484d09caf93c554b4be0c9e887d (diff) | |
download | UXP-f07d60c09fc0fea2bc614146d13346bc7473b87e.tar UXP-f07d60c09fc0fea2bc614146d13346bc7473b87e.tar.gz UXP-f07d60c09fc0fea2bc614146d13346bc7473b87e.tar.lz UXP-f07d60c09fc0fea2bc614146d13346bc7473b87e.tar.xz UXP-f07d60c09fc0fea2bc614146d13346bc7473b87e.zip |
[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.
Diffstat (limited to 'netwerk/base/nsStreamLoader.cpp')
-rw-r--r-- | netwerk/base/nsStreamLoader.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/netwerk/base/nsStreamLoader.cpp b/netwerk/base/nsStreamLoader.cpp index a73b038a7..9990d1882 100644 --- a/netwerk/base/nsStreamLoader.cpp +++ b/netwerk/base/nsStreamLoader.cpp @@ -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 |