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

Unified Diff: base/task_scheduler/scheduler_worker_pool_impl.cc

Issue 2807063007: Remove SchedulerWorkerPoolImpl::ReEnqueueSequenceCallback. (Closed)
Patch Set: Created 3 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_pool_impl.cc
diff --git a/base/task_scheduler/scheduler_worker_pool_impl.cc b/base/task_scheduler/scheduler_worker_pool_impl.cc
index 891bea0a1cfb4fc41528c1f2a9acdfb45b810363..1eaca14c0e2e35cffa4bfddacd9b8655768d56c8 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()),
@@ -254,12 +248,9 @@ void SchedulerWorkerPoolImpl::Start(const SchedulerWorkerPoolParams& params) {
// Create workers in reverse order of index so that the worker with the
// 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),
- task_tracker_, params.backward_compatibility()));
-
+ workers_[index] = make_scoped_refptr(new SchedulerWorker(
+ priority_hint_, MakeUnique<SchedulerWorkerDelegateImpl>(this, index),
+ task_tracker_, params.backward_compatibility()));
if (index >= num_wake_ups_before_start_)
idle_workers_stack_.Push(workers_[index].get());
}
@@ -306,24 +297,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) {
@@ -428,10 +401,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::
@@ -527,9 +498,10 @@ 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 sort_key = sequence->GetSortKey();
+ outer_->shared_priority_queue_.BeginTransaction()->Push(std::move(sequence),
+ sort_key);
+ // No need to wake up a worker. The current worker will soon call GetWork().
}
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