Bug 1669214 - Part 4: Add code to forward runnables from EventQueue::PutEvent to the TaskController. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D92453
This commit is contained in:
Bas Schouten 2020-10-06 19:06:57 +00:00
Родитель 00d7c9b62a
Коммит f6e295763f
5 изменённых файлов: 37 добавлений и 14 удалений

Просмотреть файл

@ -7,7 +7,9 @@
#include "mozilla/EventQueue.h" #include "mozilla/EventQueue.h"
#include "GeckoProfiler.h" #include "GeckoProfiler.h"
#include "InputTaskManager.h"
#include "nsIRunnable.h" #include "nsIRunnable.h"
#include "TaskController.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::detail; using namespace mozilla::detail;
@ -20,6 +22,29 @@ template <size_t ItemsPerPage>
void EventQueueInternal<ItemsPerPage>::PutEvent( void EventQueueInternal<ItemsPerPage>::PutEvent(
already_AddRefed<nsIRunnable>&& aEvent, EventQueuePriority aPriority, already_AddRefed<nsIRunnable>&& aEvent, EventQueuePriority aPriority,
const MutexAutoLock& aProofOfLock, mozilla::TimeDuration* aDelay) { const MutexAutoLock& aProofOfLock, mozilla::TimeDuration* aDelay) {
nsCOMPtr<nsIRunnable> event(aEvent);
if (mForwardToTC) {
TaskController* tc = TaskController::Get();
TaskManager* manager = nullptr;
if (aPriority == EventQueuePriority::InputHigh) {
if (InputTaskManager::Get()->State() ==
InputTaskManager::STATE_DISABLED) {
aPriority = EventQueuePriority::Normal;
} else {
manager = InputTaskManager::Get();
}
} else if (aPriority == EventQueuePriority::DeferredTimers ||
aPriority == EventQueuePriority::Idle) {
manager = TaskController::Get()->GetIdleTaskManager();
}
tc->DispatchRunnable(event.forget(), static_cast<uint32_t>(aPriority),
manager);
return;
}
#ifdef MOZ_GECKO_PROFILER #ifdef MOZ_GECKO_PROFILER
// Sigh, this doesn't check if this thread is being profiled // Sigh, this doesn't check if this thread is being profiled
if (profiler_is_active()) { if (profiler_is_active()) {
@ -31,7 +56,6 @@ void EventQueueInternal<ItemsPerPage>::PutEvent(
} }
#endif #endif
nsCOMPtr<nsIRunnable> event(aEvent);
mQueue.Push(std::move(event)); mQueue.Push(std::move(event));
} }

Просмотреть файл

@ -24,7 +24,7 @@ class EventQueueInternal : public AbstractEventQueue {
public: public:
static const bool SupportsPrioritization = false; static const bool SupportsPrioritization = false;
EventQueueInternal() {} explicit EventQueueInternal(bool aForwardToTC) : mForwardToTC(aForwardToTC) {}
explicit EventQueueInternal(EventQueuePriority aPriority); explicit EventQueueInternal(EventQueuePriority aPriority);
void PutEvent(already_AddRefed<nsIRunnable>&& aEvent, void PutEvent(already_AddRefed<nsIRunnable>&& aEvent,
@ -91,13 +91,17 @@ class EventQueueInternal : public AbstractEventQueue {
mozilla::Queue<mozilla::TimeStamp, ItemsPerPage> mDispatchTimes; mozilla::Queue<mozilla::TimeStamp, ItemsPerPage> mDispatchTimes;
TimeDuration mLastEventDelay; TimeDuration mLastEventDelay;
#endif #endif
// This indicates PutEvent forwards runnables to the TaskController. This
// should be true for the top level event queue on the main thread.
bool mForwardToTC;
}; };
} // namespace detail } // namespace detail
class EventQueue final : public mozilla::detail::EventQueueInternal<16> { class EventQueue final : public mozilla::detail::EventQueueInternal<16> {
public: public:
EventQueue() : mozilla::detail::EventQueueInternal<16>() {} explicit EventQueue(bool aForwardToTC = false)
: mozilla::detail::EventQueueInternal<16>(aForwardToTC) {}
explicit EventQueue(EventQueuePriority aPriority) explicit EventQueue(EventQueuePriority aPriority)
: mozilla::detail::EventQueueInternal<16>(aPriority){}; : mozilla::detail::EventQueueInternal<16>(aPriority){};
}; };
@ -106,7 +110,8 @@ template <size_t ItemsPerPage = 16>
class EventQueueSized final class EventQueueSized final
: public mozilla::detail::EventQueueInternal<ItemsPerPage> { : public mozilla::detail::EventQueueInternal<ItemsPerPage> {
public: public:
EventQueueSized() : mozilla::detail::EventQueueInternal<ItemsPerPage>() {} explicit EventQueueSized(bool aForwardToTC = false)
: mozilla::detail::EventQueueInternal<ItemsPerPage>(aForwardToTC) {}
explicit EventQueueSized(EventQueuePriority aPriority) explicit EventQueueSized(EventQueuePriority aPriority)
: mozilla::detail::EventQueueInternal<ItemsPerPage>(aPriority){}; : mozilla::detail::EventQueueInternal<ItemsPerPage>(aPriority){};
}; };

Просмотреть файл

@ -72,14 +72,6 @@ void InputTaskManager::DidRunTask() {
} }
// static // static
InputTaskManager* InputTaskManager::Get() { void InputTaskManager::Init() { gInputTaskManager = new InputTaskManager(); }
MOZ_ASSERT(NS_IsMainThread());
if (gInputTaskManager) {
return gInputTaskManager.get();
}
gInputTaskManager = new InputTaskManager();
return gInputTaskManager.get();
}
} // namespace mozilla } // namespace mozilla

Просмотреть файл

@ -40,8 +40,9 @@ class InputTaskManager : public TaskManager {
mInputHandlingStartTime = aStartTime; mInputHandlingStartTime = aStartTime;
} }
static InputTaskManager* Get(); static InputTaskManager* Get() { return gInputTaskManager.get(); }
static void Cleanup() { gInputTaskManager = nullptr; } static void Cleanup() { gInputTaskManager = nullptr; }
static void Init();
private: private:
InputTaskManager() : mInputQueueState(STATE_DISABLED) {} InputTaskManager() : mInputQueueState(STATE_DISABLED) {}

Просмотреть файл

@ -79,6 +79,7 @@ bool TaskController::Initialize() {
} }
bool TaskController::InitializeInternal() { bool TaskController::InitializeInternal() {
InputTaskManager::Init();
mMTProcessingRunnable = NS_NewRunnableFunction( mMTProcessingRunnable = NS_NewRunnableFunction(
"TaskController::ExecutePendingMTTasks()", "TaskController::ExecutePendingMTTasks()",
[]() { TaskController::Get()->ProcessPendingMTTask(); }); []() { TaskController::Get()->ProcessPendingMTTask(); });