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

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

Issue 1705253002: TaskScheduler [3/9] Task and Sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_1_scheduler_lock
Patch Set: address comments from robliao #13 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
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() = default;
15
16 bool Sequence::PushTask(scoped_ptr<Task> task) {
17 AutoSchedulerLock auto_lock(lock_);
18
19 const TaskPriorityUnderlyingType index_priority =
gab 2016/02/19 16:50:47 s/index_priority/priority_index/ ? (reads better t
fdoray 2016/02/19 22:28:30 Done.
20 static_cast<TaskPriorityUnderlyingType>(task->traits.priority());
21 ++num_tasks_per_priority_[index_priority];
22
23 queue_.push(std::move(task));
24
25 // Return true if the sequence was empty before the push.
26 return queue_.size() == 1;
27 }
28
29 const Task* Sequence::PeekTask() const {
30 AutoSchedulerLock auto_lock(lock_);
31
32 if (queue_.empty())
33 return nullptr;
34
35 return queue_.front().get();
36 }
37
38 bool Sequence::PopTask() {
39 AutoSchedulerLock auto_lock(lock_);
40 CHECK(!queue_.empty());
41
42 const TaskPriorityUnderlyingType index_priority =
43 static_cast<TaskPriorityUnderlyingType>(
44 queue_.front()->traits.priority());
45 --num_tasks_per_priority_[index_priority];
46
47 queue_.pop();
48 return queue_.empty();
49 }
50
51 SequenceSortKey Sequence::GetSortKey() const {
52 AutoSchedulerLock auto_lock(lock_);
53 CHECK(!queue_.empty());
54
55 // Find the highest task priority in the sequence.
56 static_assert(static_cast<TaskPriorityUnderlyingType>(
57 TaskPriority::HIGHEST) == kNumTaskPriorities - 1,
58 "");
gab 2016/02/19 16:50:47 "Unexpected priority range." or something? Well a
fdoray 2016/02/19 22:28:30 Removed the static_assert.
59 TaskPriority priority = TaskPriority::LOWEST;
60 for (size_t i =
gab 2016/02/19 16:50:47 s/size_t/TaskPriorityUnderlyingType/ now that we'r
fdoray 2016/02/19 22:28:30 Done.
61 static_cast<TaskPriorityUnderlyingType>(TaskPriority::HIGHEST);
62 i > static_cast<TaskPriorityUnderlyingType>(TaskPriority::LOWEST); --i) {
63 if (num_tasks_per_priority_[i] > 0) {
64 priority = static_cast<TaskPriority>(i);
65 break;
66 }
67 }
68
69 return SequenceSortKey(priority, queue_.front()->sequenced_time);
70 }
71
72 Sequence::~Sequence() = default;
73
74 } // namespace internal
75 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698