OLD | NEW |
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_PRIORITY_DISPATCH_H_ | 5 #ifndef NET_BASE_PRIORITY_DISPATCH_H_ |
6 #define NET_BASE_PRIORITY_DISPATCH_H_ | 6 #define NET_BASE_PRIORITY_DISPATCH_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 #include "net/base/priority_queue.h" | 12 #include "net/base/priority_queue.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 | 15 |
16 // A priority-based dispatcher of jobs. Dispatch order is by priority (lowest | 16 // A priority-based dispatcher of jobs. Dispatch order is by priority (highest |
17 // first) and then FIFO. The dispatcher enforces limits on the number of running | 17 // first) and then FIFO. The dispatcher enforces limits on the number of running |
18 // jobs. It never revokes a job once started. The job must call OnJobFinished | 18 // jobs. It never revokes a job once started. The job must call OnJobFinished |
19 // once it finishes in order to dispatch further jobs. | 19 // once it finishes in order to dispatch further jobs. |
20 // | 20 // |
21 // All operations are O(p) time for p priority levels. The class is fully | 21 // All operations are O(p) time for p priority levels. The class is fully |
22 // reentrant: it is safe to execute any method (incl. destructor) from within | 22 // reentrant: it is safe to execute any method (incl. destructor) from within |
23 // Job callbacks. However, this class is NOT thread-safe, which is enforced | 23 // Job callbacks. However, this class is NOT thread-safe, which is enforced |
24 // by the underlying non-thread-safe PriorityQueue. | 24 // by the underlying non-thread-safe PriorityQueue. |
25 // | 25 // |
26 class NET_EXPORT_PRIVATE PrioritizedDispatcher { | 26 class NET_EXPORT_PRIVATE PrioritizedDispatcher { |
27 public: | 27 public: |
28 class Job; | 28 class Job; |
29 typedef PriorityQueue<Job*>::Priority Priority; | 29 typedef PriorityQueue<Job*>::Priority Priority; |
30 | 30 |
31 // Describes the limits for the number of jobs started by the dispatcher. | 31 // Describes the limits for the number of jobs started by the dispatcher. |
32 // For example, |total_jobs| = 30 and |reserved_slots| = { 5, 10, 5 } | 32 // For example, |total_jobs| = 30 and |reserved_slots| = { 5, 10, 5 } |
33 // allow for at most 30 running jobs in total. If there are already 24 jobs | 33 // allow for at most 30 running jobs in total. If there are already 24 jobs |
34 // running, then there can be 6 more jobs started of which at most 1 can be | 34 // running, then there can be 6 more jobs started of which at most 1 can be |
35 // at priority 1 or 0, but the rest has to be at 0. | 35 // at priority 1 or 2, but the rest have to be at 2. |
36 struct NET_EXPORT_PRIVATE Limits { | 36 struct NET_EXPORT_PRIVATE Limits { |
37 Limits(Priority num_priorities, size_t total_jobs); | 37 Limits(Priority num_priorities, size_t total_jobs); |
38 ~Limits(); | 38 ~Limits(); |
39 | 39 |
40 // Total allowed running jobs. | 40 // Total allowed running jobs. |
41 size_t total_jobs; | 41 size_t total_jobs; |
42 // Number of slots reserved for each priority and higher. | 42 // Number of slots reserved for each priority and higher. |
43 // Sum of |reserved_slots| must be no greater than |total_jobs|. | 43 // Sum of |reserved_slots| must be no greater than |total_jobs|. |
44 std::vector<size_t> reserved_slots; | 44 std::vector<size_t> reserved_slots; |
45 }; | 45 }; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // Total number of running jobs. | 106 // Total number of running jobs. |
107 size_t num_running_jobs_; | 107 size_t num_running_jobs_; |
108 | 108 |
109 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher); | 109 DISALLOW_COPY_AND_ASSIGN(PrioritizedDispatcher); |
110 }; | 110 }; |
111 | 111 |
112 } // namespace net | 112 } // namespace net |
113 | 113 |
114 #endif // NET_BASE_PRIORITY_DISPATCH_H_ | 114 #endif // NET_BASE_PRIORITY_DISPATCH_H_ |
115 | 115 |
OLD | NEW |