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

Unified Diff: base/task_scheduler/scheduler_worker_thread.cc

Issue 1864333002: TaskScheduler: Delegate instead of callbacks for SchedulerWorkerThread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Verify that OnMainEntry isn't called more than once. 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 side-by-side diff with in-line comments
Download patch
Index: base/task_scheduler/scheduler_worker_thread.cc
diff --git a/base/task_scheduler/scheduler_worker_thread.cc b/base/task_scheduler/scheduler_worker_thread.cc
index e03726a0c09b886167d863057cb56a25def51d63..07c7097803b36fce8a178ea1ff25bc48f082ff9e 100644
--- a/base/task_scheduler/scheduler_worker_thread.cc
+++ b/base/task_scheduler/scheduler_worker_thread.cc
@@ -17,14 +17,10 @@ namespace internal {
std::unique_ptr<SchedulerWorkerThread>
SchedulerWorkerThread::CreateSchedulerWorkerThread(
ThreadPriority thread_priority,
- const Closure& main_entry_callback,
- const GetWorkCallback& get_work_callback,
- const RanTaskFromSequenceCallback& ran_task_from_sequence_callback,
+ Delegate* delegate,
TaskTracker* task_tracker) {
std::unique_ptr<SchedulerWorkerThread> worker_thread(
- new SchedulerWorkerThread(thread_priority, main_entry_callback,
- get_work_callback,
- ran_task_from_sequence_callback, task_tracker));
+ new SchedulerWorkerThread(thread_priority, delegate, task_tracker));
if (worker_thread->thread_handle_.is_null())
return nullptr;
@@ -48,20 +44,13 @@ void SchedulerWorkerThread::JoinForTesting() {
PlatformThread::Join(thread_handle_);
}
-SchedulerWorkerThread::SchedulerWorkerThread(
- ThreadPriority thread_priority,
- const Closure& main_entry_callback,
- const GetWorkCallback& get_work_callback,
- const RanTaskFromSequenceCallback& ran_task_from_sequence_callback,
- TaskTracker* task_tracker)
+SchedulerWorkerThread::SchedulerWorkerThread(ThreadPriority thread_priority,
+ Delegate* delegate,
+ TaskTracker* task_tracker)
: wake_up_event_(false, false),
- main_entry_callback_(main_entry_callback),
- get_work_callback_(get_work_callback),
- ran_task_from_sequence_callback_(ran_task_from_sequence_callback),
+ delegate_(delegate),
task_tracker_(task_tracker) {
- DCHECK(!main_entry_callback_.is_null());
- DCHECK(!get_work_callback_.is_null());
- DCHECK(!ran_task_from_sequence_callback_.is_null());
+ DCHECK(delegate_);
DCHECK(task_tracker_);
static const size_t kDefaultStackSize = 0;
@@ -70,14 +59,14 @@ SchedulerWorkerThread::SchedulerWorkerThread(
}
void SchedulerWorkerThread::ThreadMain() {
- main_entry_callback_.Run();
+ delegate_->OnMainEntry();
// A SchedulerWorkerThread starts out sleeping.
wake_up_event_.Wait();
while (!task_tracker_->shutdown_completed() && !ShouldExitForTesting()) {
// Get the sequence containing the next task to execute.
- scoped_refptr<Sequence> sequence = get_work_callback_.Run(this);
+ scoped_refptr<Sequence> sequence = delegate_->GetWork(this);
if (!sequence) {
wake_up_event_.Wait();
@@ -85,15 +74,17 @@ void SchedulerWorkerThread::ThreadMain() {
}
task_tracker_->RunTask(sequence->PeekTask());
- ran_task_from_sequence_callback_.Run(this, std::move(sequence));
+ delegate_->RanTaskFromSequence(std::move(sequence));
// Calling WakeUp() guarantees that this SchedulerWorkerThread will run
- // Tasks from Sequences returned by |get_work_callback_| until the callback
- // returns nullptr. Resetting |wake_up_event_| here doesn't break this
- // invariant and avoids a useless loop iteration before going to sleep if
- // WakeUp() is called while this SchedulerWorkerThread is awake.
+ // Tasks from Sequences returned by the GetWork() method of |delegate_|
+ // until it returns nullptr. Resetting |wake_up_event_| here doesn't break
+ // this invariant and avoids a useless loop iteration before going to sleep
+ // if WakeUp() is called while this SchedulerWorkerThread is awake.
wake_up_event_.Reset();
}
+
+ delegate_->OnMainExit();
}
bool SchedulerWorkerThread::ShouldExitForTesting() const {

Powered by Google App Engine
This is Rietveld 408576698