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

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: 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..3ae95bf065deb25856eb946808bb30e6624a5d8e 100644
--- a/base/task_scheduler/scheduler_worker_thread.cc
+++ b/base/task_scheduler/scheduler_worker_thread.cc
@@ -9,6 +9,7 @@
#include <utility>
#include "base/logging.h"
+#include "base/task_scheduler/scheduler_worker_thread_delegate.h"
#include "base/task_scheduler/task_tracker.h"
namespace base {
@@ -17,14 +18,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,
+ SchedulerWorkerThreadDelegate* 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;
@@ -50,18 +47,12 @@ void SchedulerWorkerThread::JoinForTesting() {
SchedulerWorkerThread::SchedulerWorkerThread(
ThreadPriority thread_priority,
- const Closure& main_entry_callback,
- const GetWorkCallback& get_work_callback,
- const RanTaskFromSequenceCallback& ran_task_from_sequence_callback,
+ SchedulerWorkerThreadDelegate* 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 +61,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();
robliao 2016/04/06 20:50:18 What's the plan for getting work from the single t
fdoray 2016/04/06 21:11:38 3 possible solutions: 1) Single-threaded PQ is own
robliao 2016/04/06 21:28:20 Sounds good. Just wanted to me sure this wasn't om
if (!sequence) {
wake_up_event_.Wait();
@@ -85,15 +76,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