Bug 1756017: Clean up ChannelEventQueue r=kershaw,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D139052
This commit is contained in:
Randell Jesup 2022-02-21 14:53:59 +00:00
parent f6e81d8868
commit 1d00097fa9

View File

@ -153,7 +153,10 @@ class ChannelEventQueue final {
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
bool IsEmpty() const { return mEventQueue.IsEmpty(); }
bool IsEmpty() {
MutexAutoLock lock(mMutex);
return mEventQueue.IsEmpty();
}
#endif
private:
@ -198,12 +201,10 @@ class ChannelEventQueue final {
inline void ChannelEventQueue::RunOrEnqueue(ChannelEvent* aCallback,
bool aAssertionWhenNotQueued) {
MOZ_ASSERT(aCallback);
// Events execution could be a destruction of the channel (and our own
// destructor) unless we make sure its refcount doesn't drop to 0 while this
// method is running.
nsCOMPtr<nsISupports> kungFuDeathGrip(mOwner);
Unused << kungFuDeathGrip; // Not used in this function
nsCOMPtr<nsISupports> kungFuDeathGrip;
// To avoid leaks.
UniquePtr<ChannelEvent> event(aCallback);
@ -211,9 +212,9 @@ inline void ChannelEventQueue::RunOrEnqueue(ChannelEvent* aCallback,
// To guarantee that the running event and all the events generated within
// it will be finished before events on other threads.
RecursiveMutexAutoLock lock(mRunningMutex);
{
MutexAutoLock lock(mMutex);
kungFuDeathGrip = mOwner; // must be under the lock
bool enqueue = !!mForcedCount || mSuspended || mFlushing ||
!mEventQueue.IsEmpty() ||
@ -341,8 +342,13 @@ inline void ChannelEventQueue::MaybeFlushQueue() {
// when it goes out of scope.
class MOZ_STACK_CLASS AutoEventEnqueuer {
public:
explicit AutoEventEnqueuer(ChannelEventQueue* queue)
: mEventQueue(queue), mOwner(queue->mOwner) {
explicit AutoEventEnqueuer(ChannelEventQueue* queue) : mEventQueue(queue) {
{
// Probably not actually needed, since NotifyReleasingOwner should
// only happen after this, but safer to take it in case things change
MutexAutoLock lock(queue->mMutex);
mOwner = queue->mOwner;
}
mEventQueue->StartForcedQueueing();
}
~AutoEventEnqueuer() { mEventQueue->EndForcedQueueing(); }