Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Unified Diff: base/task_scheduler/sequence.cc

Issue 2399213005: TaskScheduler: Change Sequence::PeekTask to Sequence::TakeTask. (Closed)
Patch Set: CR robliao #5 Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/task_scheduler/sequence.h ('k') | base/task_scheduler/sequence_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « base/task_scheduler/sequence.h ('k') | base/task_scheduler/sequence_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698