| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 5 #ifndef COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
| 6 #define COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 6 #define COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "components/scheduler/scheduler_export.h" | 10 #include "components/scheduler/scheduler_export.h" |
| 11 | 11 |
| 12 namespace scheduler { | 12 namespace scheduler { |
| 13 class TimeDomain; | 13 class TimeDomain; |
| 14 | 14 |
| 15 class SCHEDULER_EXPORT TaskQueue : public base::SingleThreadTaskRunner { | 15 class SCHEDULER_EXPORT TaskQueue : public base::SingleThreadTaskRunner { |
| 16 public: | 16 public: |
| 17 TaskQueue() {} | 17 TaskQueue() {} |
| 18 | 18 |
| 19 // Unregisters the task queue after which no tasks posted to it will run and | 19 // Unregisters the task queue after which no tasks posted to it will run and |
| 20 // the TaskQueueManager's reference to it will be released soon. | 20 // the TaskQueueManager's reference to it will be released soon. |
| 21 virtual void UnregisterTaskQueue() = 0; | 21 virtual void UnregisterTaskQueue() = 0; |
| 22 | 22 |
| 23 // Post a delayed task at an absolute desired run time instead of a time | |
| 24 // delta from the current time. | |
| 25 virtual bool PostDelayedTaskAt(const tracked_objects::Location& from_here, | |
| 26 const base::Closure& task, | |
| 27 base::TimeTicks desired_run_time) = 0; | |
| 28 | |
| 29 enum QueuePriority { | 23 enum QueuePriority { |
| 30 // Queues with control priority will run before any other queue, and will | 24 // Queues with control priority will run before any other queue, and will |
| 31 // explicitly starve other queues. Typically this should only be used for | 25 // explicitly starve other queues. Typically this should only be used for |
| 32 // private queues which perform control operations. | 26 // private queues which perform control operations. |
| 33 CONTROL_PRIORITY, | 27 CONTROL_PRIORITY, |
| 34 // Queues with high priority will be selected preferentially over normal or | 28 // Queues with high priority will be selected preferentially over normal or |
| 35 // best effort queues. The selector will ensure that high priority queues | 29 // best effort queues. The selector will ensure that high priority queues |
| 36 // cannot completely starve normal priority queues. | 30 // cannot completely starve normal priority queues. |
| 37 HIGH_PRIORITY, | 31 HIGH_PRIORITY, |
| 38 // Queues with normal priority are the default. | 32 // Queues with normal priority are the default. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // A queue in the EMPTY state is empty and has no tasks in either the | 78 // A queue in the EMPTY state is empty and has no tasks in either the |
| 85 // work or incoming task queue. | 79 // work or incoming task queue. |
| 86 EMPTY, | 80 EMPTY, |
| 87 // A queue in the NEEDS_PUMPING state has no tasks in the work task queue, | 81 // A queue in the NEEDS_PUMPING state has no tasks in the work task queue, |
| 88 // but has tasks in the incoming task queue which can be pumped to make them | 82 // but has tasks in the incoming task queue which can be pumped to make them |
| 89 // runnable. | 83 // runnable. |
| 90 NEEDS_PUMPING, | 84 NEEDS_PUMPING, |
| 91 // A queue in the HAS_WORK state has tasks in the work task queue which | 85 // A queue in the HAS_WORK state has tasks in the work task queue which |
| 92 // are runnable. | 86 // are runnable. |
| 93 HAS_WORK, | 87 HAS_WORK, |
| 88 // The work and incomming queues are empty but there is delayed work |
| 89 // scheduled. |
| 90 NO_IMMEDIATE_WORK, |
| 94 }; | 91 }; |
| 95 | 92 |
| 96 // Options for constructing a TaskQueue. Once set the |name|, | 93 // Options for constructing a TaskQueue. Once set the |name|, |
| 97 // |should_monitor_quiescence| and |wakeup_policy| are immutable. The | 94 // |should_monitor_quiescence| and |wakeup_policy| are immutable. The |
| 98 // |pump_policy| can be mutated with |SetPumpPolicy()|. | 95 // |pump_policy| can be mutated with |SetPumpPolicy()|. |
| 99 struct Spec { | 96 struct Spec { |
| 100 // Note |name| must have application lifetime. | 97 // Note |name| must have application lifetime. |
| 101 explicit Spec(const char* name) | 98 explicit Spec(const char* name) |
| 102 : name(name), | 99 : name(name), |
| 103 should_monitor_quiescence(false), | 100 should_monitor_quiescence(false), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 TimeDomain* time_domain; | 135 TimeDomain* time_domain; |
| 139 bool should_notify_observers; | 136 bool should_notify_observers; |
| 140 }; | 137 }; |
| 141 | 138 |
| 142 // Returns true if the queue priority is not | 139 // Returns true if the queue priority is not |
| 143 // TaskQueueSelector::DISABLED_PRIORITY. NOTE this must be called on the | 140 // TaskQueueSelector::DISABLED_PRIORITY. NOTE this must be called on the |
| 144 // thread this TaskQueue was created by. | 141 // thread this TaskQueue was created by. |
| 145 virtual bool IsQueueEnabled() const = 0; | 142 virtual bool IsQueueEnabled() const = 0; |
| 146 | 143 |
| 147 // Returns true if there no tasks in either the work or incoming task queue. | 144 // Returns true if there no tasks in either the work or incoming task queue. |
| 145 // This method ignores delayed tasks that are scheduled to run in the future. |
| 148 // Note that this function involves taking a lock, so calling it has some | 146 // Note that this function involves taking a lock, so calling it has some |
| 149 // overhead. NOTE this must be called on the thread this TaskQueue was created | 147 // overhead. NOTE this must be called on the thread this TaskQueue was created |
| 150 // by. | 148 // by. |
| 151 virtual bool IsQueueEmpty() const; | 149 virtual bool HasPendingImmediateTask() const; |
| 152 | 150 |
| 153 // Returns the QueueState. Note that this function involves taking a lock, so | 151 // Returns the QueueState. Note that this function involves taking a lock, so |
| 154 // calling it has some overhead. | 152 // calling it has some overhead. |
| 155 virtual QueueState GetQueueState() const = 0; | 153 virtual QueueState GetQueueState() const = 0; |
| 156 | 154 |
| 157 // Can be called on any thread. | 155 // Can be called on any thread. |
| 158 virtual const char* GetName() const = 0; | 156 virtual const char* GetName() const = 0; |
| 159 | 157 |
| 160 // Set the priority of the queue to |priority|. NOTE this must be called on | 158 // Set the priority of the queue to |priority|. NOTE this must be called on |
| 161 // the thread this TaskQueue was created by. | 159 // the thread this TaskQueue was created by. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 176 | 174 |
| 177 // These functions can only be called on the same thread that the task queue | 175 // These functions can only be called on the same thread that the task queue |
| 178 // manager executes its tasks on. | 176 // manager executes its tasks on. |
| 179 virtual void AddTaskObserver( | 177 virtual void AddTaskObserver( |
| 180 base::MessageLoop::TaskObserver* task_observer) = 0; | 178 base::MessageLoop::TaskObserver* task_observer) = 0; |
| 181 virtual void RemoveTaskObserver( | 179 virtual void RemoveTaskObserver( |
| 182 base::MessageLoop::TaskObserver* task_observer) = 0; | 180 base::MessageLoop::TaskObserver* task_observer) = 0; |
| 183 | 181 |
| 184 // Removes the task queue from the previous TimeDomain and adds it to | 182 // Removes the task queue from the previous TimeDomain and adds it to |
| 185 // |domain|. This is a moderately expensive operation. | 183 // |domain|. This is a moderately expensive operation. |
| 186 virtual void SetTimeDomain(const scoped_refptr<TimeDomain>& domain) = 0; | 184 virtual void SetTimeDomain(TimeDomain* domain) = 0; |
| 187 | 185 |
| 188 protected: | 186 protected: |
| 189 ~TaskQueue() override {} | 187 ~TaskQueue() override {} |
| 190 | 188 |
| 191 DISALLOW_COPY_AND_ASSIGN(TaskQueue); | 189 DISALLOW_COPY_AND_ASSIGN(TaskQueue); |
| 192 }; | 190 }; |
| 193 | 191 |
| 194 } // namespace scheduler | 192 } // namespace scheduler |
| 195 | 193 |
| 196 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ | 194 #endif // COMPONENTS_SCHEDULER_BASE_TASK_QUEUE_H_ |
| OLD | NEW |