Bug 1661881 - Part 2: Make InputTaskManager a global singleton. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D89535
This commit is contained in:
Bas Schouten 2020-09-14 12:12:06 +00:00
parent 2594ec625f
commit 1dcbec6a4f
4 changed files with 23 additions and 2 deletions

View File

@ -8,6 +8,8 @@
namespace mozilla {
StaticRefPtr<InputTaskManager> InputTaskManager::gInputTaskManager;
void InputTaskManager::EnableInputEventPrioritization() {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mInputQueueState == STATE_DISABLED);
@ -69,4 +71,15 @@ void InputTaskManager::DidRunTask() {
InputEventStatistics::Get().UpdateInputDuration(TimeStamp::Now() - start);
}
// static
InputTaskManager* InputTaskManager::Get() {
MOZ_ASSERT(NS_IsMainThread());
if (gInputTaskManager) {
return gInputTaskManager.get();
}
gInputTaskManager = new InputTaskManager();
return gInputTaskManager.get();
}
} // namespace mozilla

View File

@ -13,7 +13,6 @@ namespace mozilla {
class InputTaskManager : public TaskManager {
public:
InputTaskManager() : mInputQueueState(STATE_DISABLED) {}
int32_t GetPriorityModifierForEventLoopTurn(
const MutexAutoLock& aProofOfLock) final;
void WillRunTask() final;
@ -41,10 +40,17 @@ class InputTaskManager : public TaskManager {
mInputHandlingStartTime = aStartTime;
}
static InputTaskManager* Get();
static void Cleanup() { gInputTaskManager = nullptr; }
private:
InputTaskManager() : mInputQueueState(STATE_DISABLED) {}
TimeStamp mInputHandlingStartTime;
Atomic<InputEventQueueState> mInputQueueState;
AutoTArray<TimeStamp, 4> mStartTimes;
static StaticRefPtr<InputTaskManager> gInputTaskManager;
};
} // namespace mozilla

View File

@ -26,7 +26,7 @@ PrioritizedEventQueue::PrioritizedEventQueue(
mDeferredTimersQueue(
MakeUnique<EventQueue>(EventQueuePriority::DeferredTimers)),
mIdleQueue(MakeUnique<EventQueue>(EventQueuePriority::Idle)) {
mInputTaskManager = new InputTaskManager();
mInputTaskManager = InputTaskManager::Get();
mIdleTaskManager = new IdleTaskManager(std::move(aIdlePeriod));
TaskController::Get()->SetIdleTaskManager(mIdleTaskManager);
}

View File

@ -12,6 +12,7 @@
#include <initializer_list>
#include "mozilla/AbstractEventQueue.h"
#include "mozilla/BackgroundHangMonitor.h"
#include "mozilla/InputTaskManager.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/SchedulerGroup.h"
#include "mozilla/ScopeExit.h"
@ -95,6 +96,7 @@ void TaskController::SetPerformanceCounterState(
/* static */
void TaskController::Shutdown() {
InputTaskManager::Cleanup();
if (sSingleton) {
sSingleton->ShutdownInternal();
}