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() : num_tasks_per_priority_() {} | |
gab
2016/02/18 03:00:45
Does |num_task_per_priority_| really need to be ex
fdoray
2016/02/18 14:56:12
http://stackoverflow.com/questions/15212261/defaul
| |
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_); | |
fdoray
2016/02/18 01:46:11
Put AutoSchedulerLock first, to be consistent with
gab
2016/02/18 03:00:45
I actually like having it second but would put an
fdoray
2016/02/18 14:56:12
Done (new_num_tasks is gone)
| |
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; | |
fdoray
2016/02/18 01:46:11
This loop relies on the fact that the priority val
gab
2016/02/18 03:00:45
Agreed, also line 57 in header ( size_t num_tasks_
| |
51 for (TaskPriorityUnderlyingType i = kNumTaskPriorities - 1; i >= 0; --i) { | |
fdoray
2016/02/18 01:46:11
static_assert(std::is_signed<TaskPriorityUnderlyin
gab
2016/02/18 03:00:45
Hmmm, why? I'm actually proposing using uint8 abov
fdoray
2016/02/18 14:56:12
|i| needs to be signed. Otherwise, the i >=0 condi
| |
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 | |
OLD | NEW |