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

Side by Side Diff: base/task_scheduler/scheduler_worker_thread.cc

Issue 1862243005: TaskScheduler: Pop a Task from its Sequence from SchedulerWorkerThread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@5_pq_callback
Patch Set: CR gab #4 Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "base/task_scheduler/scheduler_worker_thread.h" 5 #include "base/task_scheduler/scheduler_worker_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 while (!task_tracker_->shutdown_completed() && !ShouldExitForTesting()) { 67 while (!task_tracker_->shutdown_completed() && !ShouldExitForTesting()) {
68 // Get the sequence containing the next task to execute. 68 // Get the sequence containing the next task to execute.
69 scoped_refptr<Sequence> sequence = delegate_->GetWork(this); 69 scoped_refptr<Sequence> sequence = delegate_->GetWork(this);
70 70
71 if (!sequence) { 71 if (!sequence) {
72 wake_up_event_.Wait(); 72 wake_up_event_.Wait();
73 continue; 73 continue;
74 } 74 }
75 75
76 task_tracker_->RunTask(sequence->PeekTask()); 76 task_tracker_->RunTask(sequence->PeekTask());
77 delegate_->RanTaskFromSequence(std::move(sequence)); 77
78 const bool sequence_became_empty = sequence->PopTask();
79
80 // If |sequence| isn't empty immediately after the pop, enqueue it to
81 // maintain the invariant that a non-empty Sequence is always referenced by
82 // either a PriorityQueue or a SchedulerWorkerThread. If it is empty, it
83 // will be enqueued when a Task is added to it.
robliao 2016/04/08 17:21:39 Nit: Technically, for the empty case... If it is e
fdoray 2016/04/08 17:49:12 Done.
84 if (!sequence_became_empty)
85 delegate_->EnqueueSequence(std::move(sequence));
78 86
79 // Calling WakeUp() guarantees that this SchedulerWorkerThread will run 87 // Calling WakeUp() guarantees that this SchedulerWorkerThread will run
80 // Tasks from Sequences returned by the GetWork() method of |delegate_| 88 // Tasks from Sequences returned by the GetWork() method of |delegate_|
81 // until it returns nullptr. Resetting |wake_up_event_| here doesn't break 89 // until it returns nullptr. Resetting |wake_up_event_| here doesn't break
82 // this invariant and avoids a useless loop iteration before going to sleep 90 // this invariant and avoids a useless loop iteration before going to sleep
83 // if WakeUp() is called while this SchedulerWorkerThread is awake. 91 // if WakeUp() is called while this SchedulerWorkerThread is awake.
84 wake_up_event_.Reset(); 92 wake_up_event_.Reset();
85 } 93 }
86 94
87 delegate_->OnMainExit(); 95 delegate_->OnMainExit();
88 } 96 }
89 97
90 bool SchedulerWorkerThread::ShouldExitForTesting() const { 98 bool SchedulerWorkerThread::ShouldExitForTesting() const {
91 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); 99 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_);
92 return should_exit_for_testing_; 100 return should_exit_for_testing_;
93 } 101 }
94 102
95 } // namespace internal 103 } // namespace internal
96 } // namespace base 104 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698