mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1869719 - dom/media ChannelMediaResource thread-safety annotations r=media-playback-reviewers,karlt
Differential Revision: https://phabricator.services.mozilla.com/D131875
This commit is contained in:
parent
6ced1f5c01
commit
7e2ca0cae5
@ -58,14 +58,14 @@ NS_IMPL_ISUPPORTS(ChannelMediaResource::Listener, nsIRequestObserver,
|
||||
nsIThreadRetargetableStreamListener)
|
||||
|
||||
nsresult ChannelMediaResource::Listener::OnStartRequest(nsIRequest* aRequest) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mMutex.AssertOnWritingThread(); // Writing thread is MainThread
|
||||
if (!mResource) return NS_OK;
|
||||
return mResource->OnStartRequest(aRequest, mOffset);
|
||||
}
|
||||
|
||||
nsresult ChannelMediaResource::Listener::OnStopRequest(nsIRequest* aRequest,
|
||||
nsresult aStatus) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mMutex.AssertOnWritingThread();
|
||||
if (!mResource) return NS_OK;
|
||||
return mResource->OnStopRequest(aRequest, aStatus);
|
||||
}
|
||||
@ -76,7 +76,7 @@ nsresult ChannelMediaResource::Listener::OnDataAvailable(
|
||||
// This might happen off the main thread.
|
||||
RefPtr<ChannelMediaResource> res;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
MutexSingleWriterAutoLock lock(mMutex);
|
||||
res = mResource;
|
||||
}
|
||||
// Note Rekove() might happen at the same time to reset mResource. We check
|
||||
@ -87,7 +87,7 @@ nsresult ChannelMediaResource::Listener::OnDataAvailable(
|
||||
nsresult ChannelMediaResource::Listener::AsyncOnChannelRedirect(
|
||||
nsIChannel* aOld, nsIChannel* aNew, uint32_t aFlags,
|
||||
nsIAsyncVerifyRedirectCallback* cb) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mMutex.AssertOnWritingThread();
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (mResource) {
|
||||
@ -114,7 +114,7 @@ nsresult ChannelMediaResource::Listener::GetInterface(const nsIID& aIID,
|
||||
|
||||
void ChannelMediaResource::Listener::Revoke() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MutexAutoLock lock(mMutex);
|
||||
MutexSingleWriterAutoLock lock(mMutex);
|
||||
mResource = nullptr;
|
||||
}
|
||||
|
||||
|
@ -168,12 +168,13 @@ class ChannelMediaResource
|
||||
|
||||
class Listener final : public nsIInterfaceRequestor,
|
||||
public nsIChannelEventSink,
|
||||
public nsIThreadRetargetableStreamListener {
|
||||
public nsIThreadRetargetableStreamListener,
|
||||
public SingleWriterLockOwner {
|
||||
~Listener() = default;
|
||||
|
||||
public:
|
||||
Listener(ChannelMediaResource* aResource, int64_t aOffset, uint32_t aLoadID)
|
||||
: mMutex("Listener.mMutex"),
|
||||
: mMutex("Listener.mMutex", this),
|
||||
mResource(aResource),
|
||||
mOffset(aOffset),
|
||||
mLoadID(aLoadID) {}
|
||||
@ -187,12 +188,14 @@ class ChannelMediaResource
|
||||
|
||||
void Revoke();
|
||||
|
||||
bool OnWritingThread() const override { return NS_IsMainThread(); }
|
||||
|
||||
private:
|
||||
Mutex mMutex MOZ_UNANNOTATED;
|
||||
MutexSingleWriter mMutex;
|
||||
// mResource should only be modified on the main thread with the lock.
|
||||
// So it can be read without lock on the main thread or on other threads
|
||||
// with the lock.
|
||||
RefPtr<ChannelMediaResource> mResource;
|
||||
RefPtr<ChannelMediaResource> mResource MOZ_GUARDED_BY(mMutex);
|
||||
|
||||
const int64_t mOffset;
|
||||
const uint32_t mLoadID;
|
||||
|
Loading…
Reference in New Issue
Block a user