Commit 6e646e94 authored by glider@chromium.org's avatar glider@chromium.org

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
parent 8857d54b
......@@ -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();
......
......@@ -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));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment