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

Side by Side Diff: content/child/shared_memory_data_consumer_handle.cc

Issue 1234213002: Fix data races on |SharedMemoryDataConsumerHandle::Context::notification_task_runner_| (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/child/shared_memory_data_consumer_handle.h" 5 #include "content/child/shared_memory_data_consumer_handle.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 notification_task_runner_->PostTask( 97 notification_task_runner_->PostTask(
98 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false)); 98 FROM_HERE, base::Bind(&Context::NotifyInternal, this, false));
99 } 99 }
100 } 100 }
101 void ReleaseReaderLock() { 101 void ReleaseReaderLock() {
102 DCHECK(notification_task_runner_); 102 DCHECK(notification_task_runner_);
103 notification_task_runner_ = nullptr; 103 notification_task_runner_ = nullptr;
104 client_ = nullptr; 104 client_ = nullptr;
105 } 105 }
106 void PostNotify() { 106 void PostNotify() {
107 auto runner = notification_task_runner_; 107 scoped_refptr<base::SingleThreadTaskRunner> runner;
108 {
109 base::AutoLock lock(lock_);
110 runner = notification_task_runner_;
111 }
108 if (!runner) 112 if (!runner)
109 return; 113 return;
110 // We don't re-post the task when the runner changes while waiting for 114 // We don't re-post the task when the runner changes while waiting for
111 // this task because in this case a new reader is obtained and 115 // this task because in this case a new reader is obtained and
112 // notification is already done at the reader creation time if necessary. 116 // notification is already done at the reader creation time if necessary.
113 runner->PostTask(FROM_HERE, 117 runner->PostTask(FROM_HERE,
114 base::Bind(&Context::NotifyInternal, this, false)); 118 base::Bind(&Context::NotifyInternal, this, false));
115 } 119 }
116 void Notify() { NotifyInternal(true); } 120 void Notify() { NotifyInternal(true); }
117 // This function doesn't work in the destructor if |on_reader_detached_| is 121 // This function doesn't work in the destructor if |on_reader_detached_| is
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 157 }
154 void set_is_two_phase_read_in_progress(bool b) { 158 void set_is_two_phase_read_in_progress(bool b) {
155 is_two_phase_read_in_progress_ = b; 159 is_two_phase_read_in_progress_ = b;
156 } 160 }
157 base::Lock& lock() { return lock_; } 161 base::Lock& lock() { return lock_; }
158 162
159 private: 163 private:
160 void NotifyInternal(bool repost) { 164 void NotifyInternal(bool repost) {
161 // Note that this function is not protected by |lock_|. 165 // Note that this function is not protected by |lock_|.
162 166
163 auto runner = notification_task_runner_; 167 scoped_refptr<base::SingleThreadTaskRunner> runner;
168 {
169 base::AutoLock lock(lock_);
170 runner = notification_task_runner_;
171 }
164 if (!runner) 172 if (!runner)
165 return; 173 return;
166 174
167 if (runner->BelongsToCurrentThread()) { 175 if (runner->BelongsToCurrentThread()) {
168 // It is safe to access member variables without lock because |client_| 176 // It is safe to access member variables without lock because |client_|
169 // is bound to the current thread. 177 // is bound to the current thread.
170 if (client_) 178 if (client_)
171 client_->didGetReadable(); 179 client_->didGetReadable();
172 return; 180 return;
173 } 181 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 bool needs_notification = false; 284 bool needs_notification = false;
277 285
278 { 286 {
279 base::AutoLock lock(context_->lock()); 287 base::AutoLock lock(context_->lock());
280 if (context_->result() == Ok) { 288 if (context_->result() == Ok) {
281 context_->set_result(Done); 289 context_->set_result(Done);
282 context_->ResetOnReaderDetached(); 290 context_->ResetOnReaderDetached();
283 needs_notification = context_->IsEmpty(); 291 needs_notification = context_->IsEmpty();
284 } 292 }
285 } 293 }
286 if (needs_notification) { 294 if (needs_notification) {
yhirano 2015/07/15 13:30:09 I decoupled this section because I though PostNoti
hiroshige 2015/07/15 21:35:40 Done. Taking one lock instead of two is at least g
287 // We cannot issue the notification synchronously because this function can 295 // We cannot issue the notification synchronously because this function can
288 // be called in the client's callback. 296 // be called in the client's callback.
289 context_->PostNotify(); 297 context_->PostNotify();
290 } 298 }
291 } 299 }
292 300
293 void SharedMemoryDataConsumerHandle::Writer::Fail() { 301 void SharedMemoryDataConsumerHandle::Writer::Fail() {
294 bool needs_notification = false; 302 bool needs_notification = false;
295 { 303 {
296 base::AutoLock lock(context_->lock()); 304 base::AutoLock lock(context_->lock());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 SharedMemoryDataConsumerHandle::ReaderImpl* 446 SharedMemoryDataConsumerHandle::ReaderImpl*
439 SharedMemoryDataConsumerHandle::obtainReaderInternal(Client* client) { 447 SharedMemoryDataConsumerHandle::obtainReaderInternal(Client* client) {
440 return new ReaderImpl(context_, client); 448 return new ReaderImpl(context_, client);
441 } 449 }
442 450
443 const char* SharedMemoryDataConsumerHandle::debugName() const { 451 const char* SharedMemoryDataConsumerHandle::debugName() const {
444 return "SharedMemoryDataConsumerHandle"; 452 return "SharedMemoryDataConsumerHandle";
445 } 453 }
446 454
447 } // namespace content 455 } // namespace content
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