Index: base/task_scheduler/sequence.cc |
diff --git a/base/task_scheduler/sequence.cc b/base/task_scheduler/sequence.cc |
index 86e99f0a4c390907f101f99cf6a08d29b86f08a7..601b5402d069b489b70f960a04931e9875c8d520 100644 |
--- a/base/task_scheduler/sequence.cc |
+++ b/base/task_scheduler/sequence.cc |
@@ -26,37 +26,32 @@ bool Sequence::PushTask(std::unique_ptr<Task> task) { |
return queue_.size() == 1; |
} |
-const Task* Sequence::PeekTask() const { |
+std::unique_ptr<Task> Sequence::TakeTask() { |
AutoSchedulerLock auto_lock(lock_); |
+ DCHECK(!queue_.empty()); |
+ DCHECK(queue_.front()); |
- if (queue_.empty()) |
- return nullptr; |
+ const int priority_index = |
+ static_cast<int>(queue_.front()->traits.priority()); |
+ DCHECK_GT(num_tasks_per_priority_[priority_index], 0U); |
+ --num_tasks_per_priority_[priority_index]; |
- return queue_.front().get(); |
+ return std::move(queue_.front()); |
} |
-bool Sequence::PopTask() { |
- // Delete the popped task outside the scope of |lock_|. This prevents a double |
- // acquisition of |lock_| if the task's destructor tries to post a task to |
- // this Sequence and reduces contention. |
- std::unique_ptr<Task> delete_outside_lock_scope; |
- bool sequence_empty_after_pop = false; |
- |
- { |
- AutoSchedulerLock auto_lock(lock_); |
- DCHECK(!queue_.empty()); |
- |
- const int priority_index = |
- static_cast<int>(queue_.front()->traits.priority()); |
- DCHECK_GT(num_tasks_per_priority_[priority_index], 0U); |
- --num_tasks_per_priority_[priority_index]; |
- |
- delete_outside_lock_scope = std::move(queue_.front()); |
- queue_.pop(); |
- sequence_empty_after_pop = queue_.empty(); |
- } |
+TaskTraits Sequence::PeekTaskTraits() const { |
+ AutoSchedulerLock auto_lock(lock_); |
+ DCHECK(!queue_.empty()); |
+ DCHECK(queue_.front()); |
+ return queue_.front()->traits; |
+} |
- return sequence_empty_after_pop; |
+bool Sequence::Pop() { |
+ AutoSchedulerLock auto_lock(lock_); |
+ DCHECK(!queue_.empty()); |
+ DCHECK(!queue_.front()); |
+ queue_.pop(); |
+ return queue_.empty(); |
} |
SequenceSortKey Sequence::GetSortKey() const { |