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

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

Issue 19498003: [net/dns] Perform A/AAAA queries for AF_UNSPEC resolutions in parallel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 7 years, 4 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 #ifndef NET_BASE_PRIORITIZED_DISPATCHER_H_ 5 #ifndef NET_BASE_PRIORITIZED_DISPATCHER_H_
6 #define NET_BASE_PRIORITIZED_DISPATCHER_H_ 6 #define NET_BASE_PRIORITIZED_DISPATCHER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "net/base/net_export.h" 10 #include "net/base/net_export.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 size_t num_running_jobs() const { return num_running_jobs_; } 71 size_t num_running_jobs() const { return num_running_jobs_; }
72 size_t num_queued_jobs() const { return queue_.size(); } 72 size_t num_queued_jobs() const { return queue_.size(); }
73 size_t num_priorities() const { return max_running_jobs_.size(); } 73 size_t num_priorities() const { return max_running_jobs_.size(); }
74 74
75 // Adds |job| with |priority| to the dispatcher. If limits permit, |job| is 75 // Adds |job| with |priority| to the dispatcher. If limits permit, |job| is
76 // started immediately. Returns handle to the job or null-handle if the job is 76 // started immediately. Returns handle to the job or null-handle if the job is
77 // started. The dispatcher does not own |job|, but |job| must live as long as 77 // started. The dispatcher does not own |job|, but |job| must live as long as
78 // it is queued in the dispatcher. 78 // it is queued in the dispatcher.
79 Handle Add(Job* job, Priority priority); 79 Handle Add(Job* job, Priority priority);
80 80
81 // Just like Add, except that it adds Job at the font of queue of jobs with
82 // priorities of |priority|.
83 Handle AddAtHead(Job* job, Priority priority);
84
81 // Removes the job with |handle| from the queue. Invalidates |handle|. 85 // Removes the job with |handle| from the queue. Invalidates |handle|.
82 // Note: a Handle is valid iff the job is in the queue, i.e. has not Started. 86 // Note: a Handle is valid iff the job is in the queue, i.e. has not Started.
83 void Cancel(const Handle& handle); 87 void Cancel(const Handle& handle);
84 88
85 // Cancels and returns the oldest-lowest-priority Job invalidating any 89 // Cancels and returns the oldest-lowest-priority Job invalidating any
86 // handles to it. Returns NULL if the queue is empty. 90 // handles to it. Returns NULL if the queue is empty.
87 Job* EvictOldestLowest(); 91 Job* EvictOldestLowest();
88 92
89 // Moves the queued job with |handle| to the end of all values with priority 93 // Moves the queued job with |handle| to the end of all values with priority
90 // |priority| and returns the updated handle, or null-handle if it starts the 94 // |priority| and returns the updated handle, or null-handle if it starts the
91 // job. Invalidates |handle|. No-op if priority did not change. 95 // job. Invalidates |handle|. No-op if priority did not change.
92 Handle ChangePriority(const Handle& handle, Priority priority); 96 Handle ChangePriority(const Handle& handle, Priority priority);
93 97
94 // Notifies the dispatcher that a running job has finished. Could start a job. 98 // Notifies the dispatcher that a running job has finished. Could start a job.
95 void OnJobFinished(); 99 void OnJobFinished();
96 100
101 // Tells the dispatcher not to start new jobs when old jobs complete or are
102 // cancelled. Can't be undone. Can be used to avoid starting new jobs during
103 // cleanup.
104 void Disable();
105
97 private: 106 private:
98 // Attempts to dispatch the job with |handle| at priority |priority| (might be 107 // Attempts to dispatch the job with |handle| at priority |priority| (might be
99 // different than |handle.priority()|. Returns true if successful. If so 108 // different than |handle.priority()|. Returns true if successful. If so
100 // the |handle| becomes invalid. 109 // the |handle| becomes invalid.
101 bool MaybeDispatchJob(const Handle& handle, Priority priority); 110 bool MaybeDispatchJob(const Handle& handle, Priority priority);
102 111
112 // Updates |max_running_jobs_| to match |limits|. Does not start any new
113 // new jobs, even if the new limits would allow queued jobs to start.
114 void SetLimits(const Limits& limits);
115
103 // Queue for jobs that need to wait for a spare slot. 116 // Queue for jobs that need to wait for a spare slot.
104 PriorityQueue<Job*> queue_; 117 PriorityQueue<Job*> queue_;
105 // Maximum total number of running jobs allowed after a job at a particular 118 // Maximum total number of running jobs allowed after a job at a particular
106 // priority is started. If a greater or equal number of jobs are running, then 119 // priority is started. If a greater or equal number of jobs are running, then
107 // another job cannot be started. 120 // another job cannot be started.
108 std::vector<size_t> max_running_jobs_; 121 std::vector<size_t> max_running_jobs_;
109 // Total number of running jobs. 122 // Total number of running jobs.
110 size_t num_running_jobs_; 123 size_t num_running_jobs_;
111 124
112 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher); 125 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher);
113 }; 126 };
114 127
115 } // namespace net 128 } // namespace net
116 129
117 #endif // NET_BASE_PRIORITIZED_DISPATCHER_H_ 130 #endif // NET_BASE_PRIORITIZED_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698