Bug 1350432 - Remove mEventObservers to SynchronizedEventQueue (r=froydnj)

MozReview-Commit-ID: 8Xt1gdxFDr4
This commit is contained in:
Bill McCloskey 2017-08-21 13:26:14 -07:00
parent 8d0e884b2f
commit 9cd553af84
5 changed files with 49 additions and 17 deletions

View File

@ -472,7 +472,7 @@ SheetLoadData::ScheduleLoadEventIfNeeded(nsresult aStatus)
mStatus = aStatus;
nsCOMPtr<nsIThread> thread = do_GetMainThread();
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
nsCOMPtr<nsIThreadInternal> internalThread = do_QueryInterface(thread);
if (NS_SUCCEEDED(internalThread->AddObserver(this))) {
// Make sure to block onload here

View File

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SynchronizedEventQueue.h"
using namespace mozilla;
void
SynchronizedEventQueue::AddObserver(nsIThreadObserver* aObserver)
{
MOZ_ASSERT(aObserver);
MOZ_ASSERT(!mEventObservers.Contains(aObserver));
mEventObservers.AppendElement(aObserver);
}
void
SynchronizedEventQueue::RemoveObserver(nsIThreadObserver* aObserver)
{
MOZ_ASSERT(aObserver);
MOZ_ALWAYS_TRUE(mEventObservers.RemoveElement(aObserver));
}
const nsTObserverArray<nsCOMPtr<nsIThreadObserver>>&
SynchronizedEventQueue::EventObservers()
{
return mEventObservers;
}

View File

@ -10,6 +10,7 @@
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/AbstractEventQueue.h"
#include "mozilla/Mutex.h"
#include "nsTObserverArray.h"
class nsIThreadObserver;
@ -65,6 +66,10 @@ public:
virtual already_AddRefed<nsIThreadObserver> GetObserverOnThread() = 0;
virtual void SetObserver(nsIThreadObserver* aObserver) = 0;
void AddObserver(nsIThreadObserver* aObserver);
void RemoveObserver(nsIThreadObserver* aObserver);
const nsTObserverArray<nsCOMPtr<nsIThreadObserver>>& EventObservers();
virtual void EnableInputEventPrioritization() = 0;
virtual void FlushInputEventPrioritization() = 0;
virtual void SuspendInputEventPrioritization() = 0;
@ -72,6 +77,9 @@ public:
protected:
virtual ~SynchronizedEventQueue() {}
private:
nsTObserverArray<nsCOMPtr<nsIThreadObserver>> mEventObservers;
};
} // namespace mozilla

View File

@ -94,6 +94,7 @@ UNIFIED_SOURCES += [
'RWLock.cpp',
'SchedulerGroup.cpp',
'SharedThreadPool.cpp',
'SynchronizedEventQueue.cpp',
'SystemGroup.cpp',
'TaskQueue.cpp',
'ThreadEventQueue.cpp',

View File

@ -874,11 +874,11 @@ void canary_alarm_handler(int signum)
#endif
#define NOTIFY_EVENT_OBSERVERS(func_, params_) \
#define NOTIFY_EVENT_OBSERVERS(observers_, func_, params_) \
do { \
if (!mEventObservers.IsEmpty()) { \
nsAutoTObserverArray<NotNull<nsCOMPtr<nsIThreadObserver>>, 2>::ForwardIterator \
iter_(mEventObservers); \
if (!observers_.IsEmpty()) { \
nsTObserverArray<nsCOMPtr<nsIThreadObserver>>::ForwardIterator \
iter_(observers_); \
nsCOMPtr<nsIThreadObserver> obs_; \
while (iter_.HasMore()) { \
obs_ = iter_.GetNext(); \
@ -951,7 +951,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
obs->OnProcessNextEvent(this, reallyWait);
}
NOTIFY_EVENT_OBSERVERS(OnProcessNextEvent, (this, reallyWait));
NOTIFY_EVENT_OBSERVERS(EventQueue()->EventObservers(), OnProcessNextEvent, (this, reallyWait));
#ifdef MOZ_CANARY
Canary canary;
@ -1039,7 +1039,7 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
}
}
NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent, (this, *aResult));
NOTIFY_EVENT_OBSERVERS(EventQueue()->EventObservers(), AfterProcessNextEvent, (this, *aResult));
if (obs) {
obs->AfterProcessNextEvent(this, *aResult);
@ -1146,13 +1146,7 @@ nsThread::AddObserver(nsIThreadObserver* aObserver)
return NS_ERROR_NOT_SAME_THREAD;
}
NS_WARNING_ASSERTION(!mEventObservers.Contains(aObserver),
"Adding an observer twice!");
if (!mEventObservers.AppendElement(WrapNotNull(aObserver))) {
NS_WARNING("Out of memory!");
return NS_ERROR_OUT_OF_MEMORY;
}
EventQueue()->AddObserver(aObserver);
return NS_OK;
}
@ -1164,9 +1158,7 @@ nsThread::RemoveObserver(nsIThreadObserver* aObserver)
return NS_ERROR_NOT_SAME_THREAD;
}
if (aObserver && !mEventObservers.RemoveElement(aObserver)) {
NS_WARNING("Removing an observer that was never added!");
}
EventQueue()->RemoveObserver(aObserver);
return NS_OK;
}