summaryrefslogtreecommitdiffstats
path: root/base/memory
diff options
context:
space:
mode:
authorglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 08:51:32 +0000
committerglider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-07 08:51:32 +0000
commit6e646e9404107153ab3930c924a1d752733a859c (patch)
tree4673d9c23c1d978d84f345db908a70f643bfc9ba /base/memory
parent8857d54b061e603d7c323106279f6cfafe9e1a8a (diff)
downloadchromium_src-6e646e9404107153ab3930c924a1d752733a859c.zip
chromium_src-6e646e9404107153ab3930c924a1d752733a859c.tar.gz
chromium_src-6e646e9404107153ab3930c924a1d752733a859c.tar.bz2
Fix base::internal::Singleton to use acquire loads instead of nobarrier ones.
The NoBarrier_Load operations don't actually guarantee that the singleton data associated with the pointer is visible to the thread calling get() even if the pointer is initialized. R=mark@chromium.org, dvyukov@chromium.org, epenner@chromium.org Review URL: https://codereview.chromium.org/188603002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255552 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/memory')
-rw-r--r--base/memory/singleton.cc5
-rw-r--r--base/memory/singleton.h5
2 files changed, 8 insertions, 2 deletions
diff --git a/base/memory/singleton.cc b/base/memory/singleton.cc
index ee5e58d..f68ecaa 100644
--- a/base/memory/singleton.cc
+++ b/base/memory/singleton.cc
@@ -18,7 +18,10 @@ subtle::AtomicWord WaitForInstance(subtle::AtomicWord* instance) {
// the object has been created.
subtle::AtomicWord value;
while (true) {
- value = subtle::NoBarrier_Load(instance);
+ // The load has acquire memory ordering as the thread which reads the
+ // instance pointer must acquire visibility over the associated data.
+ // The pairing Release_Store operation is in Singleton::get().
+ value = subtle::Acquire_Load(instance);
if (value != kBeingCreatedMarker)
break;
PlatformThread::YieldCurrentThread();
diff --git a/base/memory/singleton.h b/base/memory/singleton.h
index 355aad0..e5e2e3e 100644
--- a/base/memory/singleton.h
+++ b/base/memory/singleton.h
@@ -233,7 +233,9 @@ class Singleton {
base::ThreadRestrictions::AssertSingletonAllowed();
#endif
- base::subtle::AtomicWord value = base::subtle::NoBarrier_Load(&instance_);
+ // The load has acquire memory ordering as the thread which reads the
+ // 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_);
@@ -252,6 +254,7 @@ class Singleton {
// 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));