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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/shared_memory_data_consumer_handle.cc
diff --git a/content/child/shared_memory_data_consumer_handle.cc b/content/child/shared_memory_data_consumer_handle.cc
index f11435ada87c22572379c59ce9b80f2e50c85b44..d73bd529ba552a782f70454e120eb96041ae27a8 100644
--- a/content/child/shared_memory_data_consumer_handle.cc
+++ b/content/child/shared_memory_data_consumer_handle.cc
@@ -160,7 +160,11 @@ class SharedMemoryDataConsumerHandle::Context final
void NotifyInternal(bool repost) {
// Note that this function is not protected by |lock_|.
- auto runner = notification_task_runner_;
+ scoped_refptr<base::SingleThreadTaskRunner> runner;
+ {
+ base::AutoLock lock(lock_);
+ runner = notification_task_runner_;
+ }
if (!runner)
return;
@@ -273,44 +277,33 @@ void SharedMemoryDataConsumerHandle::Writer::AddData(
}
void SharedMemoryDataConsumerHandle::Writer::Close() {
- bool needs_notification = false;
-
- {
- base::AutoLock lock(context_->lock());
- if (context_->result() == Ok) {
- context_->set_result(Done);
- context_->ResetOnReaderDetached();
- needs_notification = context_->IsEmpty();
+ base::AutoLock lock(context_->lock());
+ if (context_->result() == Ok) {
+ context_->set_result(Done);
+ context_->ResetOnReaderDetached();
+ if (context_->IsEmpty()) {
+ // We cannot issue the notification synchronously because this function
+ // can be called in the client's callback.
+ context_->PostNotify();
kinuko 2015/07/16 03:28:44 If some methods of Context are assumed to be calle
hiroshige 2015/07/16 05:35:58 Added comments/assertions in Patch Set 4.
}
}
- if (needs_notification) {
- // We cannot issue the notification synchronously because this function can
- // be called in the client's callback.
- context_->PostNotify();
- }
}
void SharedMemoryDataConsumerHandle::Writer::Fail() {
- bool needs_notification = false;
- {
- base::AutoLock lock(context_->lock());
- if (context_->result() == Ok) {
- // TODO(yhirano): Use an appropriate error code other than
- // UnexpectedError.
- context_->set_result(UnexpectedError);
-
- if (context_->is_two_phase_read_in_progress()) {
- // If we are in two-phase read session, we cannot discard the data. We
- // will clear the queue at the end of the session.
- } else {
- context_->ClearQueue();
- }
+ base::AutoLock lock(context_->lock());
+ if (context_->result() == Ok) {
+ // TODO(yhirano): Use an appropriate error code other than
+ // UnexpectedError.
+ context_->set_result(UnexpectedError);
- context_->ResetOnReaderDetached();
- needs_notification = true;
+ if (context_->is_two_phase_read_in_progress()) {
+ // If we are in two-phase read session, we cannot discard the data. We
+ // will clear the queue at the end of the session.
+ } else {
+ context_->ClearQueue();
}
- }
- if (needs_notification) {
+
+ context_->ResetOnReaderDetached();
// We cannot issue the notification synchronously because this function can
// be called in the client's callback.
context_->PostNotify();
« 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