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

Unified Diff: base/task_scheduler/scheduler_worker_pool_impl.cc

Issue 2862143004: Remove SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback. (Closed)
Patch Set: CR-robliao-remove-includes Created 3 years, 7 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_pool_impl.cc
diff --git a/base/task_scheduler/scheduler_worker_pool_impl.cc b/base/task_scheduler/scheduler_worker_pool_impl.cc
index ad118afe3152a97fc5fc93e81c7573a4915c6613..e5ccfbdac9d37cd0e3b590b5c0fe971818c32d01 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl.cc
+++ b/base/task_scheduler/scheduler_worker_pool_impl.cc
@@ -143,13 +143,10 @@ bool ContainsWorker(const std::vector<scoped_refptr<SchedulerWorker>>& workers,
class SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl
: public SchedulerWorker::Delegate {
public:
- // |outer| owns the worker for which this delegate is constructed.
- // |re_enqueue_sequence_callback| is invoked when ReEnqueueSequence() is
- // called. |index| will be appended to the pool name to label the underlying
- // worker threads.
+ // |outer| owns the worker for which this delegate is constructed. |index|
+ // will be appended to the pool name to label the underlying worker threads.
SchedulerWorkerDelegateImpl(
SchedulerWorkerPoolImpl* outer,
- const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
int index);
~SchedulerWorkerDelegateImpl() override;
@@ -164,7 +161,6 @@ class SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl
private:
SchedulerWorkerPoolImpl* outer_;
- const ReEnqueueSequenceCallback re_enqueue_sequence_callback_;
// Time of the last detach.
TimeTicks last_detach_time_;
@@ -195,12 +191,10 @@ class SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl
SchedulerWorkerPoolImpl::SchedulerWorkerPoolImpl(
const std::string& name,
ThreadPriority priority_hint,
- ReEnqueueSequenceCallback re_enqueue_sequence_callback,
TaskTracker* task_tracker,
DelayedTaskManager* delayed_task_manager)
: name_(name),
priority_hint_(priority_hint),
- re_enqueue_sequence_callback_(std::move(re_enqueue_sequence_callback)),
idle_workers_stack_lock_(shared_priority_queue_.container_lock()),
idle_workers_stack_cv_for_testing_(
idle_workers_stack_lock_.CreateConditionVariable()),
@@ -265,9 +259,7 @@ void SchedulerWorkerPoolImpl::Start(const SchedulerWorkerPoolParams& params) {
// highest index is at the bottom of the idle stack.
for (int index = params.max_threads() - 1; index >= 0; --index) {
workers_[index] = make_scoped_refptr(new SchedulerWorker(
- priority_hint_,
- MakeUnique<SchedulerWorkerDelegateImpl>(
- this, re_enqueue_sequence_callback_, index),
+ priority_hint_, MakeUnique<SchedulerWorkerDelegateImpl>(this, index),
task_tracker_, params.backward_compatibility(),
index < num_alive_workers ? SchedulerWorker::InitialState::ALIVE
: SchedulerWorker::InitialState::DETACHED));
@@ -311,24 +303,6 @@ SchedulerWorkerPoolImpl::CreateSequencedTaskRunnerWithTraits(
return make_scoped_refptr(new SchedulerSequencedTaskRunner(traits, this));
}
-void SchedulerWorkerPoolImpl::ReEnqueueSequence(
- scoped_refptr<Sequence> sequence,
- const SequenceSortKey& sequence_sort_key) {
- shared_priority_queue_.BeginTransaction()->Push(std::move(sequence),
- sequence_sort_key);
-
- // The thread calling this method just ran a Task from |sequence| and will
- // soon try to get another Sequence from which to run a Task. If the thread
- // belongs to this pool, it will get that Sequence from
- // |shared_priority_queue_|. When that's the case, there is no need to wake up
- // another worker after |sequence| is inserted in |shared_priority_queue_|. If
- // we did wake up another worker, we would waste resources by having more
- // workers trying to get a Sequence from |shared_priority_queue_| than the
- // number of Sequences in it.
- if (tls_current_worker_pool.Get().Get() != this)
- WakeUpOneWorker();
-}
-
bool SchedulerWorkerPoolImpl::PostTaskWithSequence(
std::unique_ptr<Task> task,
scoped_refptr<Sequence> sequence) {
@@ -435,10 +409,8 @@ size_t SchedulerWorkerPoolImpl::NumberOfAliveWorkersForTesting() {
SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::
SchedulerWorkerDelegateImpl(
SchedulerWorkerPoolImpl* outer,
- const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
int index)
: outer_(outer),
- re_enqueue_sequence_callback_(re_enqueue_sequence_callback),
index_(index) {}
SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::
@@ -534,9 +506,12 @@ void SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::DidRunTask() {
void SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::
ReEnqueueSequence(scoped_refptr<Sequence> sequence) {
- // |re_enqueue_sequence_callback_| will determine in which PriorityQueue
- // |sequence| must be enqueued.
- re_enqueue_sequence_callback_.Run(std::move(sequence));
+ const SequenceSortKey sequence_sort_key = sequence->GetSortKey();
+ outer_->shared_priority_queue_.BeginTransaction()->Push(std::move(sequence),
+ sequence_sort_key);
+ // The thread calling this method will soon call GetWork(). Therefore, there
+ // is no need to wake up a worker to run the sequence that was just inserted
+ // into |outer_->shared_priority_queue_|.
}
TimeDelta SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.h ('k') | base/task_scheduler/scheduler_worker_pool_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698