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

Side by Side Diff: net/spdy/spdy_write_queue.cc

Issue 265933007: SPDY: Defer SpdyBufferProducer deletions in SpdyWriteQueue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Defer deletion using std::vector. Don't post. 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/spdy/spdy_write_queue.h" 5 #include "net/spdy/spdy_write_queue.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <vector>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util.h"
10 #include "net/spdy/spdy_buffer.h" 12 #include "net/spdy/spdy_buffer.h"
11 #include "net/spdy/spdy_buffer_producer.h" 13 #include "net/spdy/spdy_buffer_producer.h"
12 #include "net/spdy/spdy_stream.h" 14 #include "net/spdy/spdy_stream.h"
13 15
14 namespace net { 16 namespace net {
15 17
16 SpdyWriteQueue::PendingWrite::PendingWrite() : frame_producer(NULL) {} 18 SpdyWriteQueue::PendingWrite::PendingWrite() : frame_producer(NULL) {}
17 19
18 SpdyWriteQueue::PendingWrite::PendingWrite( 20 SpdyWriteQueue::PendingWrite::PendingWrite(
19 SpdyFrameType frame_type, 21 SpdyFrameType frame_type,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { 88 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) {
87 if (priority == i) 89 if (priority == i)
88 continue; 90 continue;
89 for (std::deque<PendingWrite>::const_iterator it = queue_[i].begin(); 91 for (std::deque<PendingWrite>::const_iterator it = queue_[i].begin();
90 it != queue_[i].end(); ++it) { 92 it != queue_[i].end(); ++it) {
91 DCHECK_NE(it->stream.get(), stream.get()); 93 DCHECK_NE(it->stream.get(), stream.get());
92 } 94 }
93 } 95 }
94 #endif 96 #endif
95 97
98 // Defer deletion until queue iteration is complete, as
99 // SpdyBuffer::~SpdyBuffer() can result in callbacks into SpdyWriteQueue.
100 std::vector<SpdyBufferProducer*> erased_buffer_producers;
willchan no longer on Chromium 2014/05/06 16:38:14 You can also use ScopedVector (https://code.google
Johnny 2014/05/06 16:54:27 Leaving as-is I think, to preserve explicit contro
101
96 // Do the actual deletion and removal, preserving FIFO-ness. 102 // Do the actual deletion and removal, preserving FIFO-ness.
97 std::deque<PendingWrite>* queue = &queue_[priority]; 103 std::deque<PendingWrite>* queue = &queue_[priority];
98 std::deque<PendingWrite>::iterator out_it = queue->begin(); 104 std::deque<PendingWrite>::iterator out_it = queue->begin();
99 for (std::deque<PendingWrite>::const_iterator it = queue->begin(); 105 for (std::deque<PendingWrite>::const_iterator it = queue->begin();
100 it != queue->end(); ++it) { 106 it != queue->end(); ++it) {
101 if (it->stream.get() == stream.get()) { 107 if (it->stream.get() == stream.get()) {
102 delete it->frame_producer; 108 erased_buffer_producers.push_back(it->frame_producer);
103 } else { 109 } else {
104 *out_it = *it; 110 *out_it = *it;
105 ++out_it; 111 ++out_it;
106 } 112 }
107 } 113 }
108 queue->erase(out_it, queue->end()); 114 queue->erase(out_it, queue->end());
109 removing_writes_ = false; 115 removing_writes_ = false;
116 STLDeleteElements(&erased_buffer_producers); // Invokes callbacks.
110 } 117 }
111 118
112 void SpdyWriteQueue::RemovePendingWritesForStreamsAfter( 119 void SpdyWriteQueue::RemovePendingWritesForStreamsAfter(
113 SpdyStreamId last_good_stream_id) { 120 SpdyStreamId last_good_stream_id) {
114 CHECK(!removing_writes_); 121 CHECK(!removing_writes_);
115 removing_writes_ = true; 122 removing_writes_ = true;
123 std::vector<SpdyBufferProducer*> erased_buffer_producers;
124
116 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { 125 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) {
117 // Do the actual deletion and removal, preserving FIFO-ness. 126 // Do the actual deletion and removal, preserving FIFO-ness.
118 std::deque<PendingWrite>* queue = &queue_[i]; 127 std::deque<PendingWrite>* queue = &queue_[i];
119 std::deque<PendingWrite>::iterator out_it = queue->begin(); 128 std::deque<PendingWrite>::iterator out_it = queue->begin();
120 for (std::deque<PendingWrite>::const_iterator it = queue->begin(); 129 for (std::deque<PendingWrite>::const_iterator it = queue->begin();
121 it != queue->end(); ++it) { 130 it != queue->end(); ++it) {
122 if (it->stream.get() && (it->stream->stream_id() > last_good_stream_id || 131 if (it->stream.get() && (it->stream->stream_id() > last_good_stream_id ||
123 it->stream->stream_id() == 0)) { 132 it->stream->stream_id() == 0)) {
124 delete it->frame_producer; 133 erased_buffer_producers.push_back(it->frame_producer);
125 } else { 134 } else {
126 *out_it = *it; 135 *out_it = *it;
127 ++out_it; 136 ++out_it;
128 } 137 }
129 } 138 }
130 queue->erase(out_it, queue->end()); 139 queue->erase(out_it, queue->end());
131 } 140 }
132 removing_writes_ = false; 141 removing_writes_ = false;
142 STLDeleteElements(&erased_buffer_producers); // Invokes callbacks.
133 } 143 }
134 144
135 void SpdyWriteQueue::Clear() { 145 void SpdyWriteQueue::Clear() {
136 CHECK(!removing_writes_); 146 CHECK(!removing_writes_);
137 removing_writes_ = true; 147 removing_writes_ = true;
148 std::vector<SpdyBufferProducer*> erased_buffer_producers;
149
138 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) { 150 for (int i = MINIMUM_PRIORITY; i <= MAXIMUM_PRIORITY; ++i) {
139 for (std::deque<PendingWrite>::iterator it = queue_[i].begin(); 151 for (std::deque<PendingWrite>::iterator it = queue_[i].begin();
140 it != queue_[i].end(); ++it) { 152 it != queue_[i].end(); ++it) {
141 delete it->frame_producer; 153 erased_buffer_producers.push_back(it->frame_producer);
142 } 154 }
143 queue_[i].clear(); 155 queue_[i].clear();
144 } 156 }
145 removing_writes_ = false; 157 removing_writes_ = false;
158 STLDeleteElements(&erased_buffer_producers); // Invokes callbacks.
146 } 159 }
147 160
148 } // namespace net 161 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698