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

Side by Side Diff: net/base/prioritized_dispatcher.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/prioritized_dispatcher.h" 5 #include "net/base/prioritized_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace net { 9 namespace net {
10 10
11 PrioritizedDispatcher::Limits::Limits(Priority num_priorities, 11 PrioritizedDispatcher::Limits::Limits(Priority num_priorities,
12 size_t total_jobs) 12 size_t total_jobs)
13 : total_jobs(total_jobs), reserved_slots(num_priorities) {} 13 : total_jobs(total_jobs), reserved_slots(num_priorities) {
14 }
14 15
15 PrioritizedDispatcher::Limits::~Limits() {} 16 PrioritizedDispatcher::Limits::~Limits() {
17 }
16 18
17 PrioritizedDispatcher::PrioritizedDispatcher(const Limits& limits) 19 PrioritizedDispatcher::PrioritizedDispatcher(const Limits& limits)
18 : queue_(limits.reserved_slots.size()), 20 : queue_(limits.reserved_slots.size()),
19 max_running_jobs_(limits.reserved_slots.size()), 21 max_running_jobs_(limits.reserved_slots.size()),
20 num_running_jobs_(0) { 22 num_running_jobs_(0) {
21 SetLimits(limits); 23 SetLimits(limits);
22 } 24 }
23 25
24 PrioritizedDispatcher::~PrioritizedDispatcher() {} 26 PrioritizedDispatcher::~PrioritizedDispatcher() {
27 }
25 28
26 PrioritizedDispatcher::Handle PrioritizedDispatcher::Add( 29 PrioritizedDispatcher::Handle PrioritizedDispatcher::Add(Job* job,
27 Job* job, Priority priority) { 30 Priority priority) {
28 DCHECK(job); 31 DCHECK(job);
29 DCHECK_LT(priority, num_priorities()); 32 DCHECK_LT(priority, num_priorities());
30 if (num_running_jobs_ < max_running_jobs_[priority]) { 33 if (num_running_jobs_ < max_running_jobs_[priority]) {
31 ++num_running_jobs_; 34 ++num_running_jobs_;
32 job->Start(); 35 job->Start();
33 return Handle(); 36 return Handle();
34 } 37 }
35 return queue_.Insert(job, priority); 38 return queue_.Insert(job, priority);
36 } 39 }
37 40
38 PrioritizedDispatcher::Handle PrioritizedDispatcher::AddAtHead( 41 PrioritizedDispatcher::Handle PrioritizedDispatcher::AddAtHead(
39 Job* job, Priority priority) { 42 Job* job,
43 Priority priority) {
40 DCHECK(job); 44 DCHECK(job);
41 DCHECK_LT(priority, num_priorities()); 45 DCHECK_LT(priority, num_priorities());
42 if (num_running_jobs_ < max_running_jobs_[priority]) { 46 if (num_running_jobs_ < max_running_jobs_[priority]) {
43 ++num_running_jobs_; 47 ++num_running_jobs_;
44 job->Start(); 48 job->Start();
45 return Handle(); 49 return Handle();
46 } 50 }
47 return queue_.InsertAtFront(job, priority); 51 return queue_.InsertAtFront(job, priority);
48 } 52 }
49 53
50 void PrioritizedDispatcher::Cancel(const Handle& handle) { 54 void PrioritizedDispatcher::Cancel(const Handle& handle) {
51 queue_.Erase(handle); 55 queue_.Erase(handle);
52 } 56 }
53 57
54 PrioritizedDispatcher::Job* PrioritizedDispatcher::EvictOldestLowest() { 58 PrioritizedDispatcher::Job* PrioritizedDispatcher::EvictOldestLowest() {
55 Handle handle = queue_.FirstMin(); 59 Handle handle = queue_.FirstMin();
56 if (handle.is_null()) 60 if (handle.is_null())
57 return NULL; 61 return NULL;
58 Job* job = handle.value(); 62 Job* job = handle.value();
59 Cancel(handle); 63 Cancel(handle);
60 return job; 64 return job;
61 } 65 }
62 66
63 PrioritizedDispatcher::Handle PrioritizedDispatcher::ChangePriority( 67 PrioritizedDispatcher::Handle PrioritizedDispatcher::ChangePriority(
64 const Handle& handle, Priority priority) { 68 const Handle& handle,
69 Priority priority) {
65 DCHECK(!handle.is_null()); 70 DCHECK(!handle.is_null());
66 DCHECK_LT(priority, num_priorities()); 71 DCHECK_LT(priority, num_priorities());
67 DCHECK_GE(num_running_jobs_, max_running_jobs_[handle.priority()]) << 72 DCHECK_GE(num_running_jobs_, max_running_jobs_[handle.priority()])
68 "Job should not be in queue when limits permit it to start."; 73 << "Job should not be in queue when limits permit it to start.";
69 74
70 if (handle.priority() == priority) 75 if (handle.priority() == priority)
71 return handle; 76 return handle;
72 77
73 if (MaybeDispatchJob(handle, priority)) 78 if (MaybeDispatchJob(handle, priority))
74 return Handle(); 79 return Handle();
75 Job* job = handle.value(); 80 Job* job = handle.value();
76 queue_.Erase(handle); 81 queue_.Erase(handle);
77 return queue_.Insert(job, priority); 82 return queue_.Insert(job, priority);
78 } 83 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 bool PrioritizedDispatcher::MaybeDispatchNextJob() { 141 bool PrioritizedDispatcher::MaybeDispatchNextJob() {
137 Handle handle = queue_.FirstMax(); 142 Handle handle = queue_.FirstMax();
138 if (handle.is_null()) { 143 if (handle.is_null()) {
139 DCHECK_EQ(0u, queue_.size()); 144 DCHECK_EQ(0u, queue_.size());
140 return false; 145 return false;
141 } 146 }
142 return MaybeDispatchJob(handle, handle.priority()); 147 return MaybeDispatchJob(handle, handle.priority());
143 } 148 }
144 149
145 } // namespace net 150 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698