Bug 1672597 - Part 1: Make EventQueuePriority the primary method of accessing task. r=smaug
authorBas Schouten <bschouten@mozilla.com>
Tue, 27 Oct 2020 15:29:16 +0000
changeset 554714 c86e703df3e773e8712fda0bcf864d9de3e0fd94
parent 554713 29b5f82540f0eff1203e41bab6582f599cea233f
child 554715 9cbcab2100578fca1accdfa5eca4360f131d0c5a
push id37898
push userabutkovits@mozilla.com
push dateWed, 28 Oct 2020 09:24:21 +0000
treeherdermozilla-central@83bf4fd3b1fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1672597
milestone84.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1672597 - Part 1: Make EventQueuePriority the primary method of accessing task. r=smaug This provides a cleaner API than using static_casts in code that begins directly using tasks. Differential Revision: https://phabricator.services.mozilla.com/D94409
xpcom/threads/TaskController.h
--- a/xpcom/threads/TaskController.h
+++ b/xpcom/threads/TaskController.h
@@ -30,17 +30,17 @@ class nsIThreadObserver;
 
 namespace mozilla {
 
 class Task;
 class TaskController;
 class PerformanceCounter;
 class PerformanceCounterState;
 
-const uint32_t kDefaultPriorityValue = uint32_t(EventQueuePriority::Normal);
+const EventQueuePriority kDefaultPriorityValue = EventQueuePriority::Normal;
 
 // This file contains the core classes to access the Gecko scheduler. The
 // scheduler forms a graph of prioritize tasks, and is responsible for ensuring
 // the execution of tasks or their dependencies in order of inherited priority.
 //
 // The core class is the 'Task' class. The task class describes a single unit of
 // work. Users scheduling work implement this class and are required to
 // reimplement the 'Run' function in order to do work.
@@ -166,21 +166,28 @@ class Task {
 
   // Tell the task about its idle deadline.  Will only be called for
   // tasks managed by an IdleTaskManager, right before the task runs.
   virtual void SetIdleDeadline(TimeStamp aDeadline) {}
 
   virtual PerformanceCounter* GetPerformanceCounter() const { return nullptr; }
 
  protected:
-  Task(bool aMainThreadOnly, uint32_t aPriority = kDefaultPriorityValue)
+  Task(bool aMainThreadOnly,
+       uint32_t aPriority = static_cast<uint32_t>(kDefaultPriorityValue))
       : mMainThreadOnly(aMainThreadOnly),
         mSeqNo(sCurrentTaskSeqNo++),
         mPriority(aPriority) {}
 
+  Task(bool aMainThreadOnly,
+       EventQueuePriority aPriority = kDefaultPriorityValue)
+      : mMainThreadOnly(aMainThreadOnly),
+        mSeqNo(sCurrentTaskSeqNo++),
+        mPriority(static_cast<uint32_t>(aPriority)) {}
+
   virtual ~Task() {}
 
   friend class TaskController;
 
   // When this returns false, the task is considered incomplete and will be
   // rescheduled at the current 'mPriority' level.
   virtual bool Run() = 0;