1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_SPDY_WRITE_BLOCKED_LIST_H_
6 #define NET_SPDY_WRITE_BLOCKED_LIST_H_
11 #include "base/logging.h"
15 const int kHighestPriority = 0;
16 const int kLowestPriority = 7;
18 template <typename IdType>
19 class WriteBlockedList {
21 // 0(1) size lookup. 0(1) insert at front or back.
22 typedef std::deque<IdType> BlockedList;
23 typedef typename BlockedList::iterator iterator;
25 // Returns the priority of the highest priority list with sessions on it, or
26 // -1 if none of the lists have pending sessions.
27 int GetHighestPriorityWriteBlockedList() const {
28 for (int i = 0; i <= kLowestPriority; ++i) {
29 if (write_blocked_lists_[i].size() > 0)
35 int PopFront(int priority) {
36 DCHECK(!write_blocked_lists_[priority].empty());
37 IdType stream_id = write_blocked_lists_[priority].front();
38 write_blocked_lists_[priority].pop_front();
42 bool HasWriteBlockedStreamsGreaterThanPriority(int priority) const {
43 for (int i = kHighestPriority; i < priority; ++i) {
44 if (!write_blocked_lists_[i].empty()) {
51 bool HasWriteBlockedStreams() const {
52 return HasWriteBlockedStreamsGreaterThanPriority(kLowestPriority + 1);
55 void PushBack(IdType stream_id, int priority) {
56 write_blocked_lists_[priority].push_back(stream_id);
59 void RemoveStreamFromWriteBlockedList(IdType stream_id, int priority) {
60 iterator it = std::find(write_blocked_lists_[priority].begin(),
61 write_blocked_lists_[priority].end(),
63 while (it != write_blocked_lists_[priority].end()) {
64 write_blocked_lists_[priority].erase(it);
65 it = std::find(write_blocked_lists_[priority].begin(),
66 write_blocked_lists_[priority].end(),
71 int NumBlockedStreams() {
72 int num_blocked_streams = 0;
73 for (int i = kHighestPriority; i <= kLowestPriority; ++i) {
74 num_blocked_streams += write_blocked_lists_[i].size();
76 return num_blocked_streams;
80 // Priority ranges from 0 to 7
81 BlockedList write_blocked_lists_[8];
86 #endif // NET_SPDY_WRITE_BLOCKED_LIST_H_