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

Unified Diff: base/task_scheduler/scheduler_thread_pool_impl.cc

Issue 1903133003: TaskScheduler: Avoid Sequence refcount bump in GetWork() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review:robliao/fdoray#14-15 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_thread_pool_impl.cc
diff --git a/base/task_scheduler/scheduler_thread_pool_impl.cc b/base/task_scheduler/scheduler_thread_pool_impl.cc
index 0eba0f7f0e13df7687fc995b3d7893abda4c9703..4a66cd0f7effdb3af3286c8e59478eaf526ecdc9 100644
--- a/base/task_scheduler/scheduler_thread_pool_impl.cc
+++ b/base/task_scheduler/scheduler_thread_pool_impl.cc
@@ -271,9 +271,8 @@ scoped_refptr<TaskRunner> SchedulerThreadPoolImpl::CreateTaskRunnerWithTraits(
void SchedulerThreadPoolImpl::ReEnqueueSequence(
scoped_refptr<Sequence> sequence,
const SequenceSortKey& sequence_sort_key) {
- shared_priority_queue_.BeginTransaction()->Push(
- WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence),
- 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
@@ -338,9 +337,8 @@ void SchedulerThreadPoolImpl::PostTaskWithSequenceNow(
// - A worker thread is running a Task from |sequence|. It will insert
// |sequence| in a PriorityQueue once it's done running the Task.
const auto sequence_sort_key = sequence->GetSortKey();
- priority_queue->BeginTransaction()->Push(
- WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence),
- sequence_sort_key)));
+ priority_queue->BeginTransaction()->Push(std::move(sequence),
+ sequence_sort_key);
// Wake up a worker thread to process |sequence|.
if (worker_thread)
@@ -383,20 +381,16 @@ SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl::GetWork(
DCHECK(ContainsWorkerThread(outer_->worker_threads_, worker_thread));
scoped_refptr<Sequence> sequence;
-
{
std::unique_ptr<PriorityQueue::Transaction> shared_transaction(
outer_->shared_priority_queue_.BeginTransaction());
- const auto& shared_sequence_and_sort_key = shared_transaction->Peek();
std::unique_ptr<PriorityQueue::Transaction> single_threaded_transaction(
SINGLE_THREADED_PRIORITY_QUEUE_FROM_WORKER_THREAD(worker_thread)
->BeginTransaction());
- const auto& single_threaded_sequence_and_sort_key =
- single_threaded_transaction->Peek();
- if (shared_sequence_and_sort_key.is_null() &&
- single_threaded_sequence_and_sort_key.is_null()) {
+ if (shared_transaction->IsEmpty() &&
+ single_threaded_transaction->IsEmpty()) {
single_threaded_transaction.reset();
// |shared_transaction| is kept alive while |worker_thread| is added to
@@ -415,20 +409,19 @@ SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl::GetWork(
return nullptr;
}
- if (single_threaded_sequence_and_sort_key.is_null() ||
- (!shared_sequence_and_sort_key.is_null() &&
- single_threaded_sequence_and_sort_key.sort_key <
- shared_sequence_and_sort_key.sort_key)) {
- sequence = shared_sequence_and_sort_key.sequence;
- shared_transaction->Pop();
+ if (single_threaded_transaction->IsEmpty() ||
+ (!shared_transaction->IsEmpty() &&
+ single_threaded_transaction->PeekSortKey() <
+ shared_transaction->PeekSortKey())) {
+ sequence = shared_transaction->PopSequence();
last_sequence_is_single_threaded_ = false;
} else {
- DCHECK(!single_threaded_sequence_and_sort_key.is_null());
- sequence = single_threaded_sequence_and_sort_key.sequence;
- single_threaded_transaction->Pop();
+ DCHECK(!single_threaded_transaction->IsEmpty());
+ sequence = single_threaded_transaction->PopSequence();
last_sequence_is_single_threaded_ = true;
}
}
+ DCHECK(sequence);
outer_->RemoveFromIdleWorkerThreadsStack(worker_thread);
return sequence;
@@ -441,8 +434,7 @@ void SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl::
// PriorityQueue from which it was extracted.
const SequenceSortKey sequence_sort_key = sequence->GetSortKey();
single_threaded_priority_queue_.BeginTransaction()->Push(
- WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence),
- sequence_sort_key)));
+ std::move(sequence), sequence_sort_key);
} else {
// |re_enqueue_sequence_callback_| will determine in which PriorityQueue
// |sequence| must be enqueued.

Powered by Google App Engine
This is Rietveld 408576698