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

Side by Side Diff: base/task_scheduler/scheduler_worker.cc

Issue 2399213005: TaskScheduler: Change Sequence::PeekTask to Sequence::TakeTask. (Closed)
Patch Set: CR robliao #5 Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/scheduler_worker.h" 5 #include "base/task_scheduler/scheduler_worker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 DCHECK_EQ(detached_thread.get(), this); 63 DCHECK_EQ(detached_thread.get(), this);
64 PlatformThread::Detach(thread_handle_); 64 PlatformThread::Detach(thread_handle_);
65 outer_ = nullptr; 65 outer_ = nullptr;
66 break; 66 break;
67 } 67 }
68 } 68 }
69 WaitForWork(); 69 WaitForWork();
70 continue; 70 continue;
71 } 71 }
72 72
73 const Task* task = sequence->PeekTask(); 73 std::unique_ptr<Task> task = sequence->TakeTask();
74 const TimeTicks start_time = TimeTicks::Now(); 74 const TaskPriority task_priority = task->traits.priority();
75 if (outer_->task_tracker_->RunTask(task, sequence->token())) 75 const TimeDelta task_latency = TimeTicks::Now() - task->sequenced_time;
76 outer_->delegate_->DidRunTask(task, start_time - task->sequenced_time); 76 if (outer_->task_tracker_->RunTask(std::move(task), sequence->token()))
77 outer_->delegate_->DidRunTaskWithPriority(task_priority, task_latency);
77 78
78 const bool sequence_became_empty = sequence->PopTask(); 79 const bool sequence_became_empty = sequence->Pop();
79 80
80 // If |sequence| isn't empty immediately after the pop, re-enqueue it to 81 // If |sequence| isn't empty immediately after the pop, re-enqueue it to
81 // maintain the invariant that a non-empty Sequence is always referenced 82 // maintain the invariant that a non-empty Sequence is always referenced
82 // by either a PriorityQueue or a SchedulerWorker. If it is empty 83 // by either a PriorityQueue or a SchedulerWorker. If it is empty
83 // and there are live references to it, it will be enqueued when a Task is 84 // and there are live references to it, it will be enqueued when a Task is
84 // added to it. Otherwise, it will be destroyed at the end of this scope. 85 // added to it. Otherwise, it will be destroyed at the end of this scope.
85 if (!sequence_became_empty) 86 if (!sequence_became_empty)
86 outer_->delegate_->ReEnqueueSequence(std::move(sequence)); 87 outer_->delegate_->ReEnqueueSequence(std::move(sequence));
87 88
88 // Calling WakeUp() guarantees that this SchedulerWorker will run 89 // Calling WakeUp() guarantees that this SchedulerWorker will run
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 CreateThread(); 270 CreateThread();
270 } 271 }
271 272
272 bool SchedulerWorker::ShouldExitForTesting() const { 273 bool SchedulerWorker::ShouldExitForTesting() const {
273 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_); 274 AutoSchedulerLock auto_lock(should_exit_for_testing_lock_);
274 return should_exit_for_testing_; 275 return should_exit_for_testing_;
275 } 276 }
276 277
277 } // namespace internal 278 } // namespace internal
278 } // namespace base 279 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker.h ('k') | base/task_scheduler/scheduler_worker_pool_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698