OLD | NEW |
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/priority_queue.h" | 5 #include "base/task_scheduler/priority_queue.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 namespace internal { | 13 namespace internal { |
13 | 14 |
14 PriorityQueue::SequenceAndSortKey::SequenceAndSortKey() | 15 PriorityQueue::SequenceAndSortKey::SequenceAndSortKey() |
15 : sort_key(TaskPriority::LOWEST, TimeTicks()) {} | 16 : sort_key(TaskPriority::LOWEST, TimeTicks()) {} |
16 | 17 |
17 PriorityQueue::SequenceAndSortKey::SequenceAndSortKey( | 18 PriorityQueue::SequenceAndSortKey::SequenceAndSortKey( |
18 scoped_refptr<Sequence> sequence, | 19 scoped_refptr<Sequence> sequence, |
19 const SequenceSortKey& sort_key) | 20 const SequenceSortKey& sort_key) |
(...skipping 13 matching lines...) Expand all Loading... |
33 // Run the sequence insertion callback once for each Sequence that was | 34 // Run the sequence insertion callback once for each Sequence that was |
34 // inserted in the PriorityQueue during the lifetime of this Transaction. | 35 // inserted in the PriorityQueue during the lifetime of this Transaction. |
35 // Perform this outside the scope of PriorityQueue's lock to avoid imposing an | 36 // Perform this outside the scope of PriorityQueue's lock to avoid imposing an |
36 // unnecessary lock dependency on |sequence_inserted_callback_|'s destination. | 37 // unnecessary lock dependency on |sequence_inserted_callback_|'s destination. |
37 auto_lock_.reset(); | 38 auto_lock_.reset(); |
38 for (size_t i = 0; i < num_pushed_sequences_; ++i) | 39 for (size_t i = 0; i < num_pushed_sequences_; ++i) |
39 outer_queue_->sequence_inserted_callback_.Run(); | 40 outer_queue_->sequence_inserted_callback_.Run(); |
40 } | 41 } |
41 | 42 |
42 void PriorityQueue::Transaction::Push( | 43 void PriorityQueue::Transaction::Push( |
43 scoped_ptr<SequenceAndSortKey> sequence_and_sort_key) { | 44 std::unique_ptr<SequenceAndSortKey> sequence_and_sort_key) { |
44 DCHECK(CalledOnValidThread()); | 45 DCHECK(CalledOnValidThread()); |
45 DCHECK(!sequence_and_sort_key->is_null()); | 46 DCHECK(!sequence_and_sort_key->is_null()); |
46 | 47 |
47 outer_queue_->container_.push(std::move(sequence_and_sort_key)); | 48 outer_queue_->container_.push(std::move(sequence_and_sort_key)); |
48 ++num_pushed_sequences_; | 49 ++num_pushed_sequences_; |
49 } | 50 } |
50 | 51 |
51 const PriorityQueue::SequenceAndSortKey& PriorityQueue::Transaction::Peek() | 52 const PriorityQueue::SequenceAndSortKey& PriorityQueue::Transaction::Peek() |
52 const { | 53 const { |
53 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
(...skipping 20 matching lines...) Expand all Loading... |
74 PriorityQueue::PriorityQueue(const Closure& sequence_inserted_callback, | 75 PriorityQueue::PriorityQueue(const Closure& sequence_inserted_callback, |
75 const PriorityQueue* predecessor_priority_queue) | 76 const PriorityQueue* predecessor_priority_queue) |
76 : container_lock_(&predecessor_priority_queue->container_lock_), | 77 : container_lock_(&predecessor_priority_queue->container_lock_), |
77 sequence_inserted_callback_(sequence_inserted_callback) { | 78 sequence_inserted_callback_(sequence_inserted_callback) { |
78 DCHECK(!sequence_inserted_callback_.is_null()); | 79 DCHECK(!sequence_inserted_callback_.is_null()); |
79 DCHECK(predecessor_priority_queue); | 80 DCHECK(predecessor_priority_queue); |
80 } | 81 } |
81 | 82 |
82 PriorityQueue::~PriorityQueue() = default; | 83 PriorityQueue::~PriorityQueue() = default; |
83 | 84 |
84 scoped_ptr<PriorityQueue::Transaction> PriorityQueue::BeginTransaction() { | 85 std::unique_ptr<PriorityQueue::Transaction> PriorityQueue::BeginTransaction() { |
85 return make_scoped_ptr(new Transaction(this)); | 86 return WrapUnique(new Transaction(this)); |
86 } | 87 } |
87 | 88 |
88 } // namespace internal | 89 } // namespace internal |
89 } // namespace base | 90 } // namespace base |
OLD | NEW |