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

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

Issue 1698183005: Reference CL for the new task scheduler. (Closed) Base URL: https://luckyluke-private.googlesource.com/src@bigmaster2
Patch Set: Created 4 years, 10 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
« no previous file with comments | « base/task_scheduler/sequence.h ('k') | base/task_scheduler/sequence_sort_key.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/task_scheduler/sequence.h"
6
7 #include <utility>
8
9 #include "base/logging.h"
10
11 namespace base {
12 namespace internal {
13
14 Sequence::Sequence() : num_tasks_per_priority_() {}
15
16 void Sequence::PushTask(scoped_ptr<Task> task, size_t* prev_num_tasks) {
17 AutoSchedulerLock auto_lock(lock_);
18
19 ++num_tasks_per_priority_[static_cast<TaskPriorityUnderlyingType>(
20 task->traits.priority())];
21 *prev_num_tasks = queue_.size();
22 queue_.push(std::move(task));
23 }
24
25 const Task* Sequence::PeekTask() {
26 AutoSchedulerLock auto_lock(lock_);
27
28 if (queue_.empty())
29 return nullptr;
30
31 return queue_.front().get();
32 }
33
34 void Sequence::PopTask(size_t* new_num_tasks) {
35 DCHECK(new_num_tasks);
36 AutoSchedulerLock auto_lock(lock_);
37 DCHECK(!queue_.empty());
38
39 --num_tasks_per_priority_[static_cast<TaskPriorityUnderlyingType>(
40 queue_.front()->traits.priority())];
41 queue_.pop();
42 *new_num_tasks = queue_.size();
43 }
44
45 SequenceSortKey Sequence::GetSortKey() {
46 AutoSchedulerLock auto_lock(lock_);
47 DCHECK(!queue_.empty());
48
49 // Find the highest task priority in the sequence.
50 TaskPriority priority = TaskPriority::BACKGROUND;
51 for (TaskPriorityUnderlyingType i = kNumTaskPriorities - 1; i >= 0; --i) {
52 if (num_tasks_per_priority_[i] > 0) {
53 priority = static_cast<TaskPriority>(i);
54 break;
55 }
56 }
57
58 return SequenceSortKey(priority, queue_.front()->post_time);
59 }
60
61 Sequence::~Sequence() = default;
62
63 } // namespace internal
64 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/sequence.h ('k') | base/task_scheduler/sequence_sort_key.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698