1 // Copyright 2016 The Chromium Authors 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/thread_pool/task_source_sort_key.h" 6 7 namespace base { 8 namespace internal { 9 10 static_assert(sizeof(TaskSourceSortKey) <= 2 * sizeof(uint64_t), 11 "Members in TaskSourceSortKey should be ordered to be compact."); 12 TaskSourceSortKey(TaskPriority priority,TimeTicks ready_time,uint8_t worker_count)13TaskSourceSortKey::TaskSourceSortKey(TaskPriority priority, 14 TimeTicks ready_time, 15 uint8_t worker_count) 16 : priority_(priority), 17 worker_count_(worker_count), 18 ready_time_(ready_time) {} 19 operator <(const TaskSourceSortKey & other) const20bool TaskSourceSortKey::operator<(const TaskSourceSortKey& other) const { 21 // This TaskSourceSortKey is considered more important than |other| if it has 22 // a higher priority or if it has the same priority but fewer workers, or if 23 // it has the same priority and same worker count but its next task was 24 // posted sooner than |other|'s. 25 26 // A lower priority is considered less important. 27 if (priority_ != other.priority_) 28 return priority_ < other.priority_; 29 30 // A greater worker count is considered less important. 31 if (worker_count_ != other.worker_count_) 32 return worker_count_ > other.worker_count_; 33 34 // Lastly, a greater ready time is considered less important. 35 return ready_time_ > other.ready_time_; 36 } 37 38 } // namespace internal 39 } // namespace base 40