mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1350432
- Remove mEventObservers to SynchronizedEventQueue (r=froydnj)
MozReview-Commit-ID: 8Xt1gdxFDr4
This commit is contained in:
parent
8d0e884b2f
commit
9cd553af84
@ -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
|
||||
|
31
xpcom/threads/SynchronizedEventQueue.cpp
Normal file
31
xpcom/threads/SynchronizedEventQueue.cpp
Normal 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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -94,6 +94,7 @@ UNIFIED_SOURCES += [
|
||||
'RWLock.cpp',
|
||||
'SchedulerGroup.cpp',
|
||||
'SharedThreadPool.cpp',
|
||||
'SynchronizedEventQueue.cpp',
|
||||
'SystemGroup.cpp',
|
||||
'TaskQueue.cpp',
|
||||
'ThreadEventQueue.cpp',
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user