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

Unified Diff: base/memory/singleton.h

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « base/memory/scoped_ptr_unittest.cc ('k') | base/process/process_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/singleton.h
diff --git a/base/memory/singleton.h b/base/memory/singleton.h
index e50bdc05f34eeecefc293529e7eeab0e9da0bbde..e5e2e3efed08527f0172d9b6b85866eaf8a37ea2 100644
--- a/base/memory/singleton.h
+++ b/base/memory/singleton.h
@@ -23,6 +23,7 @@
#include "base/atomicops.h"
#include "base/base_export.h"
#include "base/memory/aligned_memory.h"
+#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_restrictions.h"
namespace base {
@@ -236,6 +237,8 @@ class Singleton {
// instance_ pointer must acquire visibility over the singleton data.
base::subtle::AtomicWord value = base::subtle::Acquire_Load(&instance_);
if (value != 0 && value != base::internal::kBeingCreatedMarker) {
+ // See the corresponding HAPPENS_BEFORE below.
+ ANNOTATE_HAPPENS_AFTER(&instance_);
return reinterpret_cast<Type*>(value);
}
@@ -247,6 +250,10 @@ class Singleton {
// stop right after we do this store.
Type* newval = Traits::New();
+ // This annotation helps race detectors recognize correct lock-less
+ // synchronization between different threads calling get().
+ // See the corresponding HAPPENS_AFTER below and above.
+ ANNOTATE_HAPPENS_BEFORE(&instance_);
// Releases the visibility over instance_ to the readers.
base::subtle::Release_Store(
&instance_, reinterpret_cast<base::subtle::AtomicWord>(newval));
@@ -260,6 +267,8 @@ class Singleton {
// We hit a race. Wait for the other thread to complete it.
value = base::internal::WaitForInstance(&instance_);
+ // See the corresponding HAPPENS_BEFORE above.
+ ANNOTATE_HAPPENS_AFTER(&instance_);
return reinterpret_cast<Type*>(value);
}
« no previous file with comments | « base/memory/scoped_ptr_unittest.cc ('k') | base/process/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698