From 25a1b0f61f5a8dae2650730fe063dd62d9523874 Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Fri, 9 Oct 2020 17:56:34 +0000 Subject: [PATCH] Bug 1669256 - Part 1: Remove AbstractEventQueue and de-templatize ThreadEventQueue. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D92709 --- accessible/base/EventQueue.cpp | 7 +- dom/base/TimeoutExecutor.cpp | 2 +- dom/storage/StorageDBThread.cpp | 3 +- dom/workers/WorkerPrivate.cpp | 6 +- dom/workers/WorkerThread.cpp | 6 +- dom/worklet/WorkletThread.cpp | 6 +- ipc/chromium/src/base/thread.cc | 5 +- netwerk/cache2/CacheIOThread.cpp | 4 +- .../antitracking/ContentBlockingNotifier.cpp | 2 +- widget/android/AndroidUiThread.cpp | 6 +- xpcom/threads/AbstractEventQueue.h | 105 ------------------ xpcom/threads/EventQueue.cpp | 8 +- xpcom/threads/EventQueue.h | 77 +++++++++---- xpcom/threads/SchedulerGroup.h | 2 +- xpcom/threads/SynchronizedEventQueue.h | 2 +- xpcom/threads/TaskController.cpp | 2 +- xpcom/threads/ThreadEventQueue.cpp | 88 +++++---------- xpcom/threads/ThreadEventQueue.h | 22 ++-- xpcom/threads/moz.build | 1 - xpcom/threads/nsThread.h | 1 - xpcom/threads/nsThreadManager.cpp | 8 +- xpcom/threads/nsThreadUtils.h | 2 +- 22 files changed, 128 insertions(+), 237 deletions(-) delete mode 100644 xpcom/threads/AbstractEventQueue.h diff --git a/accessible/base/EventQueue.cpp b/accessible/base/EventQueue.cpp index 1169f94da336..638b2c5b3077 100644 --- a/accessible/base/EventQueue.cpp +++ b/accessible/base/EventQueue.cpp @@ -15,8 +15,8 @@ # include "Logging.h" #endif -using namespace mozilla; -using namespace mozilla::a11y; +namespace mozilla { +namespace a11y { // Defines the number of selection add/remove events in the queue when they // aren't packed into single selection within event. @@ -330,3 +330,6 @@ void EventQueue::ProcessEventQueue() { if (!mDocument) return; } } + +} // namespace a11y +} // namespace mozilla diff --git a/dom/base/TimeoutExecutor.cpp b/dom/base/TimeoutExecutor.cpp index b4622282f3ba..5720f250e7af 100644 --- a/dom/base/TimeoutExecutor.cpp +++ b/dom/base/TimeoutExecutor.cpp @@ -6,7 +6,7 @@ #include "TimeoutExecutor.h" -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/dom/TimeoutManager.h" #include "nsComponentManagerUtils.h" #include "nsIEventTarget.h" diff --git a/dom/storage/StorageDBThread.cpp b/dom/storage/StorageDBThread.cpp index 7054eb1dba4e..b2b6754ce3af 100644 --- a/dom/storage/StorageDBThread.cpp +++ b/dom/storage/StorageDBThread.cpp @@ -406,8 +406,7 @@ void StorageDBThread::SetDefaultPriority() { void StorageDBThread::ThreadFunc(void* aArg) { { - auto queue = - MakeRefPtr>(MakeUnique()); + auto queue = MakeRefPtr(MakeUnique()); Unused << nsThreadManager::get().CreateCurrentThread( queue, nsThread::NOT_MAIN_THREAD); } diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 4c2f959042e9..e84bcfe6a2a4 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -3842,8 +3842,7 @@ already_AddRefed WorkerPrivate::CreateNewSyncLoop( } } - auto queue = - static_cast*>(mThread->EventQueue()); + auto queue = static_cast(mThread->EventQueue()); nsCOMPtr realEventTarget = queue->PushEventQueue(); MOZ_ASSERT(realEventTarget); @@ -3966,8 +3965,7 @@ bool WorkerPrivate::DestroySyncLoop(uint32_t aLoopIndex) { bool result = loopInfo->mResult; - auto queue = - static_cast*>(mThread->EventQueue()); + auto queue = static_cast(mThread->EventQueue()); queue->PopEventQueue(nestedEventTarget); // Are we making a 1 -> 0 transition here? diff --git a/dom/workers/WorkerThread.cpp b/dom/workers/WorkerThread.cpp index 5213efca8383..bffa4ed81322 100644 --- a/dom/workers/WorkerThread.cpp +++ b/dom/workers/WorkerThread.cpp @@ -66,9 +66,9 @@ class WorkerThread::Observer final : public nsIThreadObserver { }; WorkerThread::WorkerThread(ConstructorKey) - : nsThread(MakeNotNull*>( - MakeUnique()), - nsThread::NOT_MAIN_THREAD, kWorkerStackSize), + : nsThread( + MakeNotNull(MakeUnique()), + nsThread::NOT_MAIN_THREAD, kWorkerStackSize), mLock("WorkerThread::mLock"), mWorkerPrivateCondVar(mLock, "WorkerThread::mWorkerPrivateCondVar"), mWorkerPrivate(nullptr), diff --git a/dom/worklet/WorkletThread.cpp b/dom/worklet/WorkletThread.cpp index ca6b0b31eeb7..5f4008eab7b7 100644 --- a/dom/worklet/WorkletThread.cpp +++ b/dom/worklet/WorkletThread.cpp @@ -249,9 +249,9 @@ class WorkletThread::TerminateRunnable final : public Runnable { }; WorkletThread::WorkletThread(WorkletImpl* aWorkletImpl) - : nsThread(MakeNotNull*>( - MakeUnique()), - nsThread::NOT_MAIN_THREAD, kWorkletStackSize), + : nsThread( + MakeNotNull(MakeUnique()), + nsThread::NOT_MAIN_THREAD, kWorkletStackSize), mWorkletImpl(aWorkletImpl), mExitLoop(false), mIsTerminating(false) { diff --git a/ipc/chromium/src/base/thread.cc b/ipc/chromium/src/base/thread.cc index 546c6586f487..dd470e32331a 100644 --- a/ipc/chromium/src/base/thread.cc +++ b/ipc/chromium/src/base/thread.cc @@ -154,9 +154,8 @@ void Thread::ThreadMain() { auto loopType = startup_data_->options.message_loop_type; if (loopType == MessageLoop::TYPE_MOZILLA_NONMAINTHREAD || loopType == MessageLoop::TYPE_MOZILLA_NONMAINUITHREAD) { - auto queue = - mozilla::MakeRefPtr>( - mozilla::MakeUnique()); + auto queue = mozilla::MakeRefPtr( + mozilla::MakeUnique()); xpcomThread = nsThreadManager::get().CreateCurrentThread( queue, nsThread::NOT_MAIN_THREAD); } else { diff --git a/netwerk/cache2/CacheIOThread.cpp b/netwerk/cache2/CacheIOThread.cpp index 17a0ee7cdeb3..56ad36ace150 100644 --- a/netwerk/cache2/CacheIOThread.cpp +++ b/netwerk/cache2/CacheIOThread.cpp @@ -426,8 +426,8 @@ void CacheIOThread::ThreadFunc() { MOZ_ASSERT(mBlockingIOWatcher); mBlockingIOWatcher->InitThread(); - auto queue = MakeRefPtr>( - MakeUnique()); + auto queue = + MakeRefPtr(MakeUnique()); nsCOMPtr xpcomThread = nsThreadManager::get().CreateCurrentThread(queue, nsThread::NOT_MAIN_THREAD); diff --git a/toolkit/components/antitracking/ContentBlockingNotifier.cpp b/toolkit/components/antitracking/ContentBlockingNotifier.cpp index 98301977b4b9..d63326fa3495 100644 --- a/toolkit/components/antitracking/ContentBlockingNotifier.cpp +++ b/toolkit/components/antitracking/ContentBlockingNotifier.cpp @@ -8,7 +8,7 @@ #include "ContentBlockingNotifier.h" #include "AntiTrackingUtils.h" -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/StaticPrefs_privacy.h" #include "mozilla/dom/BrowserChild.h" #include "mozilla/dom/BrowsingContext.h" diff --git a/widget/android/AndroidUiThread.cpp b/widget/android/AndroidUiThread.cpp index 1c12f34bd253..48e6f4e0b176 100644 --- a/widget/android/AndroidUiThread.cpp +++ b/widget/android/AndroidUiThread.cpp @@ -53,9 +53,9 @@ class AndroidUiThread : public nsThread { public: NS_INLINE_DECL_REFCOUNTING_INHERITED(AndroidUiThread, nsThread) AndroidUiThread() - : nsThread(MakeNotNull*>( - MakeUnique()), - nsThread::NOT_MAIN_THREAD, 0) {} + : nsThread( + MakeNotNull(MakeUnique()), + nsThread::NOT_MAIN_THREAD, 0) {} nsresult Dispatch(already_AddRefed aEvent, uint32_t aFlags) override; diff --git a/xpcom/threads/AbstractEventQueue.h b/xpcom/threads/AbstractEventQueue.h deleted file mode 100644 index 58c8fd1a4b1b..000000000000 --- a/xpcom/threads/AbstractEventQueue.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- 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/. */ - -#ifndef mozilla_AbstractEventQueue_h -#define mozilla_AbstractEventQueue_h - -#include "mozilla/AlreadyAddRefed.h" -#include "mozilla/MemoryReporting.h" -#include "mozilla/TimeStamp.h" -#include "mozilla/Mutex.h" - -class nsIRunnable; - -namespace mozilla { - -enum class EventQueuePriority { - Idle, - DeferredTimers, - InputLow, - Normal, - MediumHigh, - InputHigh, - High, - - Count -}; - -// AbstractEventQueue is an abstract base class for all our unsynchronized event -// queue implementations: -// - EventQueue: A queue of runnables. Used for non-main threads. -// - PrioritizedEventQueue: Contains a queue for each priority level. -// Has heuristics to decide which queue to pop from. Events are -// pushed into the queue corresponding to their priority. -// Used for the main thread. -// -// Since AbstractEventQueue implementations are unsynchronized, they should be -// wrapped in an outer SynchronizedEventQueue implementation (like -// ThreadEventQueue). -// -// Subclasses should also define a `static const bool SupportsPrioritization` -// member to indicate whether the subclass cares about runnable priorities -// implemented through nsIRunnablePriority. -class AbstractEventQueue { - public: - // Add an event to the end of the queue. Implementors are free to use - // aPriority however they wish. If the runnable supports - // nsIRunnablePriority and the implementing class supports - // prioritization, aPriority represents the result of calling - // nsIRunnablePriority::GetPriority(). *aDelay is time the event has - // already been delayed (used when moving an event from one queue to - // another) - virtual void PutEvent(already_AddRefed&& aEvent, - EventQueuePriority aPriority, - const MutexAutoLock& aProofOfLock, - mozilla::TimeDuration* aDelay = nullptr) = 0; - - // Get an event from the front of the queue. aPriority is an out param. If the - // implementation supports priorities, then this should be the same priority - // that the event was pushed with. aPriority may be null. This should return - // null if the queue is non-empty but the event in front is not ready to run. - // *aLastEventDelay is the time the event spent in queues before being - // retrieved. - virtual already_AddRefed GetEvent( - EventQueuePriority* aPriority, const MutexAutoLock& aProofOfLock, - mozilla::TimeDuration* aLastEventDelay = nullptr) = 0; - - // Returns true if the queue is empty. Implies !HasReadyEvent(). - virtual bool IsEmpty(const MutexAutoLock& aProofOfLock) = 0; - - // Returns true if the queue is non-empty and if the event in front is ready - // to run. Implies !IsEmpty(). This should return true iff GetEvent returns a - // non-null value. - virtual bool HasReadyEvent(const MutexAutoLock& aProofOfLock) = 0; - - virtual bool HasPendingHighPriorityEvents( - const MutexAutoLock& aProofOfLock) = 0; - - // Returns the number of events in the queue. - virtual size_t Count(const MutexAutoLock& aProofOfLock) const = 0; - - virtual void EnableInputEventPrioritization( - const MutexAutoLock& aProofOfLock) = 0; - virtual void FlushInputEventPrioritization( - const MutexAutoLock& aProofOfLock) = 0; - virtual void SuspendInputEventPrioritization( - const MutexAutoLock& aProofOfLock) = 0; - virtual void ResumeInputEventPrioritization( - const MutexAutoLock& aProofOfLock) = 0; - - size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { - return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); - } - - virtual size_t SizeOfExcludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const = 0; - - virtual ~AbstractEventQueue() = default; -}; - -} // namespace mozilla - -#endif // mozilla_AbstractEventQueue_h diff --git a/xpcom/threads/EventQueue.cpp b/xpcom/threads/EventQueue.cpp index 766494f3dcef..cfd2706be719 100644 --- a/xpcom/threads/EventQueue.cpp +++ b/xpcom/threads/EventQueue.cpp @@ -14,10 +14,6 @@ using namespace mozilla; using namespace mozilla::detail; -template -EventQueueInternal::EventQueueInternal( - EventQueuePriority aPriority) {} - template void EventQueueInternal::PutEvent( already_AddRefed&& aEvent, EventQueuePriority aPriority, @@ -122,4 +118,8 @@ size_t EventQueueInternal::Count( namespace mozilla { template class EventQueueSized<16>; // Used by ThreadEventQueue template class EventQueueSized<64>; // Used by ThrottledEventQueue +namespace detail { +template class EventQueueInternal<16>; // Used by ThreadEventQueue +template class EventQueueInternal<64>; // Used by ThrottledEventQueue +} // namespace detail } // namespace mozilla diff --git a/xpcom/threads/EventQueue.h b/xpcom/threads/EventQueue.h index 4ac607c9cf9a..5f3ea5db30a8 100644 --- a/xpcom/threads/EventQueue.h +++ b/xpcom/threads/EventQueue.h @@ -7,7 +7,7 @@ #ifndef mozilla_EventQueue_h #define mozilla_EventQueue_h -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/Mutex.h" #include "mozilla/Queue.h" #include "nsCOMPtr.h" @@ -15,24 +15,53 @@ class nsIRunnable; namespace mozilla { +enum class EventQueuePriority { + Idle, + DeferredTimers, + InputLow, + Normal, + MediumHigh, + InputHigh, + High, + + Count +}; + class IdlePeriodState; namespace detail { +// EventQueue is our unsynchronized event queue implementation. It is a queue +// of runnables used for non-main thread, as well as optionally providing +// forwarding to TaskController. +// +// Since EventQueue is unsynchronized, it should be wrapped in an outer +// SynchronizedEventQueue implementation (like ThreadEventQueue). template -class EventQueueInternal : public AbstractEventQueue { +class EventQueueInternal { public: - static const bool SupportsPrioritization = false; - explicit EventQueueInternal(bool aForwardToTC) : mForwardToTC(aForwardToTC) {} - explicit EventQueueInternal(EventQueuePriority aPriority); + // Add an event to the end of the queue. Implementors are free to use + // aPriority however they wish. If the runnable supports + // nsIRunnablePriority and the implementing class supports + // prioritization, aPriority represents the result of calling + // nsIRunnablePriority::GetPriority(). *aDelay is time the event has + // already been delayed (used when moving an event from one queue to + // another) void PutEvent(already_AddRefed&& aEvent, EventQueuePriority aPriority, const MutexAutoLock& aProofOfLock, - mozilla::TimeDuration* aDelay = nullptr) final; + mozilla::TimeDuration* aDelay = nullptr); + + // Get an event from the front of the queue. aPriority is an out param. If the + // implementation supports priorities, then this should be the same priority + // that the event was pushed with. aPriority may be null. This should return + // null if the queue is non-empty but the event in front is not ready to run. + // *aLastEventDelay is the time the event spent in queues before being + // retrieved. already_AddRefed GetEvent( EventQueuePriority* aPriority, const MutexAutoLock& aProofOfLock, - mozilla::TimeDuration* aLastEventDelay = nullptr) final; + mozilla::TimeDuration* aLastEventDelay = nullptr); already_AddRefed GetEvent(EventQueuePriority* aPriority, const MutexAutoLock& aProofOfLock, TimeDuration* aLastEventDelay, @@ -43,14 +72,20 @@ class EventQueueInternal : public AbstractEventQueue { void DidRunEvent(const MutexAutoLock& aProofOfLock) {} - bool IsEmpty(const MutexAutoLock& aProofOfLock) final; - bool HasReadyEvent(const MutexAutoLock& aProofOfLock) final; - bool HasPendingHighPriorityEvents(const MutexAutoLock& aProofOfLock) final { + // Returns true if the queue is empty. Implies !HasReadyEvent(). + bool IsEmpty(const MutexAutoLock& aProofOfLock); + + // Returns true if the queue is non-empty and if the event in front is ready + // to run. Implies !IsEmpty(). This should return true iff GetEvent returns a + // non-null value. + bool HasReadyEvent(const MutexAutoLock& aProofOfLock); + bool HasPendingHighPriorityEvents(const MutexAutoLock& aProofOfLock) { // EventQueueInternal doesn't support any prioritization. return false; } - size_t Count(const MutexAutoLock& aProofOfLock) const final; + // Returns the number of events in the queue. + size_t Count(const MutexAutoLock& aProofOfLock) const; // For some reason, if we put this in the .cpp file the linker can't find it already_AddRefed PeekEvent(const MutexAutoLock& aProofOfLock) { if (mQueue.IsEmpty()) { @@ -61,12 +96,13 @@ class EventQueueInternal : public AbstractEventQueue { return result.forget(); } - void EnableInputEventPrioritization(const MutexAutoLock& aProofOfLock) final { - } - void FlushInputEventPrioritization(const MutexAutoLock& aProofOfLock) final {} - void SuspendInputEventPrioritization( - const MutexAutoLock& aProofOfLock) final {} - void ResumeInputEventPrioritization(const MutexAutoLock& aProofOfLock) final { + void EnableInputEventPrioritization(const MutexAutoLock& aProofOfLock) {} + void FlushInputEventPrioritization(const MutexAutoLock& aProofOfLock) {} + void SuspendInputEventPrioritization(const MutexAutoLock& aProofOfLock) {} + void ResumeInputEventPrioritization(const MutexAutoLock& aProofOfLock) {} + + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); } IdlePeriodState* GetIdlePeriodState() const { return nullptr; } @@ -75,8 +111,7 @@ class EventQueueInternal : public AbstractEventQueue { return false; } - size_t SizeOfExcludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override { + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { size_t size = mQueue.ShallowSizeOfExcludingThis(aMallocSizeOf); #ifdef MOZ_GECKO_PROFILER size += mDispatchTimes.ShallowSizeOfExcludingThis(aMallocSizeOf); @@ -102,8 +137,6 @@ class EventQueue final : public mozilla::detail::EventQueueInternal<16> { public: explicit EventQueue(bool aForwardToTC = false) : mozilla::detail::EventQueueInternal<16>(aForwardToTC) {} - explicit EventQueue(EventQueuePriority aPriority) - : mozilla::detail::EventQueueInternal<16>(aPriority){}; }; template @@ -112,8 +145,6 @@ class EventQueueSized final public: explicit EventQueueSized(bool aForwardToTC = false) : mozilla::detail::EventQueueInternal(aForwardToTC) {} - explicit EventQueueSized(EventQueuePriority aPriority) - : mozilla::detail::EventQueueInternal(aPriority){}; }; } // namespace mozilla diff --git a/xpcom/threads/SchedulerGroup.h b/xpcom/threads/SchedulerGroup.h index 826068a5c11f..342cbc69452c 100644 --- a/xpcom/threads/SchedulerGroup.h +++ b/xpcom/threads/SchedulerGroup.h @@ -7,7 +7,7 @@ #ifndef mozilla_SchedulerGroup_h #define mozilla_SchedulerGroup_h -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/AlreadyAddRefed.h" #include "mozilla/LinkedList.h" #include "mozilla/Queue.h" diff --git a/xpcom/threads/SynchronizedEventQueue.h b/xpcom/threads/SynchronizedEventQueue.h index 5c6317144146..a8e258ac37e3 100644 --- a/xpcom/threads/SynchronizedEventQueue.h +++ b/xpcom/threads/SynchronizedEventQueue.h @@ -8,7 +8,7 @@ #define mozilla_SynchronizedEventQueue_h #include "mozilla/AlreadyAddRefed.h" -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/MemoryReporting.h" #include "mozilla/Mutex.h" #include "nsIThreadInternal.h" diff --git a/xpcom/threads/TaskController.cpp b/xpcom/threads/TaskController.cpp index 5d7e76d0c48b..1bd5ed64befb 100644 --- a/xpcom/threads/TaskController.cpp +++ b/xpcom/threads/TaskController.cpp @@ -10,7 +10,7 @@ #include "nsThreadUtils.h" #include #include -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/BackgroundHangMonitor.h" #include "mozilla/InputTaskManager.h" #include "mozilla/StaticMutex.h" diff --git a/xpcom/threads/ThreadEventQueue.cpp b/xpcom/threads/ThreadEventQueue.cpp index 97831d697260..a3bd62848427 100644 --- a/xpcom/threads/ThreadEventQueue.cpp +++ b/xpcom/threads/ThreadEventQueue.cpp @@ -17,8 +17,7 @@ using namespace mozilla; -template -class ThreadEventQueue::NestedSink : public ThreadTargetSink { +class ThreadEventQueue::NestedSink : public ThreadTargetSink { public: NestedSink(EventQueue* aQueue, ThreadEventQueue* aOwner) : mQueue(aQueue), mOwner(aOwner) {} @@ -46,9 +45,8 @@ class ThreadEventQueue::NestedSink : public ThreadTargetSink { RefPtr mOwner; }; -template -ThreadEventQueue::ThreadEventQueue(UniquePtr aQueue, - bool aIsMainThread) +ThreadEventQueue::ThreadEventQueue(UniquePtr aQueue, + bool aIsMainThread) : mBaseQueue(std::move(aQueue)), mLock("ThreadEventQueue"), mEventsAvailable(mLock, "EventsAvail"), @@ -56,25 +54,18 @@ ThreadEventQueue::ThreadEventQueue(UniquePtr aQueue, if (aIsMainThread) { TaskController::Get()->SetConditionVariable(&mEventsAvailable); } - static_assert(std::is_base_of::value, - "InnerQueueT must be an AbstractEventQueue subclass"); } -template -ThreadEventQueue::~ThreadEventQueue() { - MOZ_ASSERT(mNestedQueues.IsEmpty()); -} +ThreadEventQueue::~ThreadEventQueue() { MOZ_ASSERT(mNestedQueues.IsEmpty()); } -template -bool ThreadEventQueue::PutEvent( - already_AddRefed&& aEvent, EventQueuePriority aPriority) { +bool ThreadEventQueue::PutEvent(already_AddRefed&& aEvent, + EventQueuePriority aPriority) { return PutEventInternal(std::move(aEvent), aPriority, nullptr); } -template -bool ThreadEventQueue::PutEventInternal( - already_AddRefed&& aEvent, EventQueuePriority aPriority, - NestedSink* aSink) { +bool ThreadEventQueue::PutEventInternal(already_AddRefed&& aEvent, + EventQueuePriority aPriority, + NestedSink* aSink) { // We want to leak the reference when we fail to dispatch it, so that // we won't release the event in a wrong thread. LeakRefPtr event(std::move(aEvent)); @@ -135,8 +126,7 @@ bool ThreadEventQueue::PutEventInternal( return true; } -template -already_AddRefed ThreadEventQueue::GetEvent( +already_AddRefed ThreadEventQueue::GetEvent( bool aMayWait, EventQueuePriority* aPriority, mozilla::TimeDuration* aLastEventDelay) { nsCOMPtr event; @@ -230,8 +220,7 @@ already_AddRefed ThreadEventQueue::GetEvent( return event.forget(); } -template -void ThreadEventQueue::DidRunEvent() { +void ThreadEventQueue::DidRunEvent() { MutexAutoLock lock(mLock); if (mNestedQueues.IsEmpty()) { mBaseQueue->DidRunEvent(lock); @@ -242,8 +231,7 @@ void ThreadEventQueue::DidRunEvent() { } } -template -bool ThreadEventQueue::HasPendingEvent() { +bool ThreadEventQueue::HasPendingEvent() { MutexAutoLock lock(mLock); // We always get events from the topmost queue when there are nested queues. @@ -254,8 +242,7 @@ bool ThreadEventQueue::HasPendingEvent() { } } -template -bool ThreadEventQueue::HasPendingHighPriorityEvents() { +bool ThreadEventQueue::HasPendingHighPriorityEvents() { MutexAutoLock lock(mLock); // We always get events from the topmost queue when there are nested queues. @@ -267,8 +254,7 @@ bool ThreadEventQueue::HasPendingHighPriorityEvents() { } } -template -bool ThreadEventQueue::ShutdownIfNoPendingEvents() { +bool ThreadEventQueue::ShutdownIfNoPendingEvents() { MutexAutoLock lock(mLock); if (mNestedQueues.IsEmpty() && mBaseQueue->IsEmpty(lock)) { mEventsAreDoomed = true; @@ -277,33 +263,27 @@ bool ThreadEventQueue::ShutdownIfNoPendingEvents() { return false; } -template -void ThreadEventQueue::EnableInputEventPrioritization() { +void ThreadEventQueue::EnableInputEventPrioritization() { MutexAutoLock lock(mLock); mBaseQueue->EnableInputEventPrioritization(lock); } -template -void ThreadEventQueue::FlushInputEventPrioritization() { +void ThreadEventQueue::FlushInputEventPrioritization() { MutexAutoLock lock(mLock); mBaseQueue->FlushInputEventPrioritization(lock); } -template -void ThreadEventQueue::SuspendInputEventPrioritization() { +void ThreadEventQueue::SuspendInputEventPrioritization() { MutexAutoLock lock(mLock); mBaseQueue->SuspendInputEventPrioritization(lock); } -template -void ThreadEventQueue::ResumeInputEventPrioritization() { +void ThreadEventQueue::ResumeInputEventPrioritization() { MutexAutoLock lock(mLock); mBaseQueue->ResumeInputEventPrioritization(lock); } -template -already_AddRefed -ThreadEventQueue::PushEventQueue() { +already_AddRefed ThreadEventQueue::PushEventQueue() { auto queue = MakeUnique(); RefPtr sink = new NestedSink(queue.get(), this); RefPtr eventTarget = @@ -315,8 +295,7 @@ ThreadEventQueue::PushEventQueue() { return eventTarget.forget(); } -template -void ThreadEventQueue::PopEventQueue(nsIEventTarget* aTarget) { +void ThreadEventQueue::PopEventQueue(nsIEventTarget* aTarget) { MutexAutoLock lock(mLock); MOZ_ASSERT(!mNestedQueues.IsEmpty()); @@ -328,11 +307,10 @@ void ThreadEventQueue::PopEventQueue(nsIEventTarget* aTarget) { // Disconnect the event target that will be popped. item.mEventTarget->Disconnect(lock); - AbstractEventQueue* prevQueue = + EventQueue* prevQueue = mNestedQueues.Length() == 1 - ? static_cast(mBaseQueue.get()) - : static_cast( - mNestedQueues[mNestedQueues.Length() - 2].mQueue.get()); + ? mBaseQueue.get() + : mNestedQueues[mNestedQueues.Length() - 2].mQueue.get(); // Move events from the old queue to the new one. nsCOMPtr event; @@ -346,8 +324,7 @@ void ThreadEventQueue::PopEventQueue(nsIEventTarget* aTarget) { mNestedQueues.RemoveLastElement(); } -template -size_t ThreadEventQueue::SizeOfExcludingThis( +size_t ThreadEventQueue::SizeOfExcludingThis( mozilla::MallocSizeOf aMallocSizeOf) const { size_t n = 0; @@ -361,21 +338,16 @@ size_t ThreadEventQueue::SizeOfExcludingThis( return SynchronizedEventQueue::SizeOfExcludingThis(aMallocSizeOf) + n; } -template -already_AddRefed -ThreadEventQueue::GetObserver() { +already_AddRefed ThreadEventQueue::GetObserver() { MutexAutoLock lock(mLock); return do_AddRef(mObserver); } -template -already_AddRefed -ThreadEventQueue::GetObserverOnThread() { +already_AddRefed ThreadEventQueue::GetObserverOnThread() { return do_AddRef(mObserver); } -template -void ThreadEventQueue::SetObserver(nsIThreadObserver* aObserver) { +void ThreadEventQueue::SetObserver(nsIThreadObserver* aObserver) { MutexAutoLock lock(mLock); mObserver = aObserver; if (NS_IsMainThread()) { @@ -383,6 +355,6 @@ void ThreadEventQueue::SetObserver(nsIThreadObserver* aObserver) { } } -namespace mozilla { -template class ThreadEventQueue; -} // namespace mozilla +ThreadEventQueue::NestedQueueItem::NestedQueueItem( + UniquePtr aQueue, ThreadEventTarget* aEventTarget) + : mQueue(std::move(aQueue)), mEventTarget(aEventTarget) {} diff --git a/xpcom/threads/ThreadEventQueue.h b/xpcom/threads/ThreadEventQueue.h index 80160e7c2f05..ab6a49955304 100644 --- a/xpcom/threads/ThreadEventQueue.h +++ b/xpcom/threads/ThreadEventQueue.h @@ -7,7 +7,7 @@ #ifndef mozilla_ThreadEventQueue_h #define mozilla_ThreadEventQueue_h -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/CondVar.h" #include "mozilla/SynchronizedEventQueue.h" #include "nsCOMPtr.h" @@ -23,14 +23,13 @@ class EventQueue; class ThreadEventTarget; // A ThreadEventQueue implements normal monitor-style synchronization over the -// InnerQueueT AbstractEventQueue. It also implements PushEventQueue and -// PopEventQueue for workers (see the documentation below for an explanation of -// those). All threads use a ThreadEventQueue as their event queue. InnerQueueT -// is a template parameter to avoid virtual dispatch overhead. -template +// EventQueue. It also implements PushEventQueue and PopEventQueue for workers +// (see the documentation below for an explanation of those). All threads use a +// ThreadEventQueue as their event queue. Although for the main thread this +// simply forwards events to the TaskController. class ThreadEventQueue final : public SynchronizedEventQueue { public: - explicit ThreadEventQueue(UniquePtr aQueue, + explicit ThreadEventQueue(UniquePtr aQueue, bool aIsMainThread = false); bool PutEvent(already_AddRefed&& aEvent, @@ -72,15 +71,14 @@ class ThreadEventQueue final : public SynchronizedEventQueue { bool PutEventInternal(already_AddRefed&& aEvent, EventQueuePriority aPriority, NestedSink* aQueue); - UniquePtr mBaseQueue; + UniquePtr mBaseQueue; struct NestedQueueItem { UniquePtr mQueue; RefPtr mEventTarget; NestedQueueItem(UniquePtr aQueue, - ThreadEventTarget* aEventTarget) - : mQueue(std::move(aQueue)), mEventTarget(aEventTarget) {} + ThreadEventTarget* aEventTarget); }; nsTArray mNestedQueues; @@ -93,8 +91,6 @@ class ThreadEventQueue final : public SynchronizedEventQueue { bool mIsMainThread; }; -extern template class ThreadEventQueue; - -}; // namespace mozilla +} // namespace mozilla #endif // mozilla_ThreadEventQueue_h diff --git a/xpcom/threads/moz.build b/xpcom/threads/moz.build index 2b0c70caa899..f31fbc894b06 100644 --- a/xpcom/threads/moz.build +++ b/xpcom/threads/moz.build @@ -41,7 +41,6 @@ EXPORTS += [ ] EXPORTS.mozilla += [ - 'AbstractEventQueue.h', 'AbstractThread.h', 'BlockingResourceBase.h', 'CondVar.h', diff --git a/xpcom/threads/nsThread.h b/xpcom/threads/nsThread.h index a8d915219412..c4ff2eccf5d6 100644 --- a/xpcom/threads/nsThread.h +++ b/xpcom/threads/nsThread.h @@ -32,7 +32,6 @@ namespace mozilla { class CycleCollectedJSContext; class EventQueue; -template class ThreadEventQueue; class ThreadEventTarget; } // namespace mozilla diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index 4f7cfe823e96..9176ba5d22fa 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -382,8 +382,8 @@ nsresult nsThreadManager::Init() { // construct main thread. UniquePtr queue = MakeUnique(true); - RefPtr> synchronizedQueue = - new ThreadEventQueue(std::move(queue), true); + RefPtr synchronizedQueue = + new ThreadEventQueue(std::move(queue), true); mMainThread = new nsThread(WrapNotNull(synchronizedQueue), nsThread::MAIN_THREAD, 0); @@ -629,8 +629,8 @@ nsThreadManager::NewNamedThread(const nsACString& aName, uint32_t aStackSize, return NS_ERROR_NOT_INITIALIZED; } - RefPtr> queue = - new ThreadEventQueue(MakeUnique()); + RefPtr queue = + new ThreadEventQueue(MakeUnique()); RefPtr thr = new nsThread(WrapNotNull(queue), nsThread::NOT_MAIN_THREAD, aStackSize); nsresult rv = diff --git a/xpcom/threads/nsThreadUtils.h b/xpcom/threads/nsThreadUtils.h index 951fad236caa..e1cd094d6271 100644 --- a/xpcom/threads/nsThreadUtils.h +++ b/xpcom/threads/nsThreadUtils.h @@ -11,7 +11,7 @@ #include #include "MainThreadUtils.h" -#include "mozilla/AbstractEventQueue.h" +#include "mozilla/EventQueue.h" #include "mozilla/AbstractThread.h" #include "mozilla/Atomics.h" #include "mozilla/Likely.h"