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

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

Issue 1704113002: TaskScheduler [6] SchedulerWorkerThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_4_shutdown
Patch Set: CR from robliao Created 4 years, 9 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/sequence_sort_key.h" 5 #include "base/task_scheduler/sequence_sort_key.h"
6 6
7 namespace base { 7 namespace base {
8 namespace internal { 8 namespace internal {
9 9
10 SequenceSortKey::SequenceSortKey() : priority(TaskPriority::LOWEST) {}
11
10 SequenceSortKey::SequenceSortKey(TaskPriority priority, 12 SequenceSortKey::SequenceSortKey(TaskPriority priority,
11 TimeTicks next_task_sequenced_time) 13 TimeTicks next_task_sequenced_time)
12 : priority(priority), next_task_sequenced_time(next_task_sequenced_time) {} 14 : priority(priority), next_task_sequenced_time(next_task_sequenced_time) {}
13 15
14 bool SequenceSortKey::operator<(const SequenceSortKey& other) const { 16 bool SequenceSortKey::operator<(const SequenceSortKey& other) const {
15 // This SequenceSortKey is considered less important than |other| if it has a 17 // This SequenceSortKey is considered less important than |other| if it has a
16 // lower priority or if it has the same priority but its next task was posted 18 // lower priority or if it has the same priority but its next task was posted
17 // later than |other|'s. 19 // later than |other|'s.
18 const int priority_diff = 20 const int priority_diff =
19 static_cast<TaskPriorityUnderlyingType>(priority) - 21 static_cast<TaskPriorityUnderlyingType>(priority) -
20 static_cast<TaskPriorityUnderlyingType>(other.priority); 22 static_cast<TaskPriorityUnderlyingType>(other.priority);
21 return priority_diff != 0 23 return priority_diff != 0
22 ? priority_diff < 0 24 ? priority_diff < 0
23 : next_task_sequenced_time > other.next_task_sequenced_time; 25 : next_task_sequenced_time > other.next_task_sequenced_time;
24 } 26 }
25 27
26 bool SequenceSortKey::operator>(const SequenceSortKey& other) const { 28 bool SequenceSortKey::operator>(const SequenceSortKey& other) const {
27 const int priority_diff = 29 const int priority_diff =
28 static_cast<TaskPriorityUnderlyingType>(priority) - 30 static_cast<TaskPriorityUnderlyingType>(priority) -
29 static_cast<TaskPriorityUnderlyingType>(other.priority); 31 static_cast<TaskPriorityUnderlyingType>(other.priority);
30 return priority_diff != 0 32 return priority_diff != 0
31 ? priority_diff > 0 33 ? priority_diff > 0
32 : next_task_sequenced_time < other.next_task_sequenced_time; 34 : next_task_sequenced_time < other.next_task_sequenced_time;
33 } 35 }
34 36
35 } // namespace internal 37 } // namespace internal
36 } // namespace base 38 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698