Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 ++num_tasks_per_priority_[static_cast<TaskPriorityUnderlyingType>( | |
|
robliao
2016/02/19 02:33:43
Maybe a temporary for the static_cast would make t
fdoray
2016/02/19 14:12:14
Done.
| |
| 20 task->traits.priority())]; | |
| 21 queue_.push(std::move(task)); | |
| 22 | |
| 23 // Return true if the sequence was empty before the push. | |
| 24 return queue_.size() == 1; | |
| 25 } | |
| 26 | |
| 27 const Task* Sequence::PeekTask() const { | |
| 28 AutoSchedulerLock auto_lock(lock_); | |
| 29 | |
| 30 if (queue_.empty()) | |
| 31 return nullptr; | |
| 32 | |
| 33 return queue_.front().get(); | |
| 34 } | |
| 35 | |
| 36 bool Sequence::PopTask() { | |
| 37 AutoSchedulerLock auto_lock(lock_); | |
| 38 DCHECK(!queue_.empty()); | |
|
robliao
2016/02/19 02:33:43
I'm thinking this should be a CHECK. It is undefin
fdoray
2016/02/19 14:12:14
Done.
https://www.chromium.org/developers/coding-
gab
2016/02/19 16:50:47
I don't think this should be a CHECK.
It's enforc
fdoray
2016/02/19 22:28:29
Done. I do prefer DCHECK, but I agreed to change i
gab
2016/02/22 17:12:21
Agreed that for identifiable user input errors a n
fdoray
2016/02/22 18:07:54
Ack.
| |
| 39 | |
| 40 --num_tasks_per_priority_[static_cast<TaskPriorityUnderlyingType>( | |
| 41 queue_.front()->traits.priority())]; | |
| 42 queue_.pop(); | |
| 43 return queue_.empty(); | |
| 44 } | |
| 45 | |
| 46 SequenceSortKey Sequence::GetSortKey() const { | |
| 47 AutoSchedulerLock auto_lock(lock_); | |
| 48 DCHECK(!queue_.empty()); | |
|
fdoray
2016/02/19 14:12:14
CHECK here too, because front() has an undefined b
| |
| 49 | |
| 50 // Find the highest task priority in the sequence. | |
| 51 TaskPriority priority = TaskPriority::LOWEST; | |
| 52 for (size_t i = | |
| 53 static_cast<TaskPriorityUnderlyingType>(TaskPriority::HIGHEST); | |
| 54 i > static_cast<TaskPriorityUnderlyingType>(TaskPriority::LOWEST); --i) { | |
| 55 if (num_tasks_per_priority_[i] > 0) { | |
| 56 priority = static_cast<TaskPriority>(i); | |
| 57 break; | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 return SequenceSortKey(priority, queue_.front()->sequenced_time); | |
| 62 } | |
| 63 | |
| 64 Sequence::~Sequence() = default; | |
| 65 | |
| 66 } // namespace internal | |
| 67 } // namespace base | |
| OLD | NEW |