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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/task_scheduler/priority_queue.h ('k') | base/task_scheduler/priority_queue_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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
OLDNEW
« no previous file with comments | « base/task_scheduler/priority_queue.h ('k') | base/task_scheduler/priority_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698