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

Unified Diff: base/task_scheduler/sequence.cc

Issue 2164103002: TaskScheduler: Don't delete Tasks in the scope of a Sequence's lock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | base/task_scheduler/sequence_unittest.cc » ('j') | base/task_scheduler/sequence_unittest.cc » ('J')
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 4ecb60568cb88a6c013a3fb23d94c629fa22135e..c4619d4be4a1d34e64f9b7b8d63566e4b8c1d01d 100644
--- a/base/task_scheduler/sequence.cc
+++ b/base/task_scheduler/sequence.cc
@@ -36,6 +36,11 @@ const Task* Sequence::PeekTask() const {
}
bool Sequence::PopTask() {
+ // Delete the popped task outside the scope of |lock_|. That prevents a double
gab 2016/07/20 20:34:51 s/That/This/
fdoray 2016/07/21 13:36:03 Done.
+ // 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;
+
AutoSchedulerLock auto_lock(lock_);
robliao 2016/07/20 22:39:00 This would be more robust and clearer if AutoSched
fdoray 2016/07/21 13:36:03 Done.
DCHECK(!queue_.empty());
@@ -44,6 +49,7 @@ bool Sequence::PopTask() {
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();
return queue_.empty();
}
« no previous file with comments | « no previous file | base/task_scheduler/sequence_unittest.cc » ('j') | base/task_scheduler/sequence_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698