Add support for indeterminate checkbox on Windows classic theme.
[chromium-blink-merge.git] / base / memory / singleton.cc
blobee5e58d0057776807780471afdc439c97856d4c9
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/singleton.h"
6 #include "base/threading/platform_thread.h"
8 namespace base {
9 namespace internal {
11 subtle::AtomicWord WaitForInstance(subtle::AtomicWord* instance) {
12 // Handle the race. Another thread beat us and either:
13 // - Has the object in BeingCreated state
14 // - Already has the object created...
15 // We know value != NULL. It could be kBeingCreatedMarker, or a valid ptr.
16 // Unless your constructor can be very time consuming, it is very unlikely
17 // to hit this race. When it does, we just spin and yield the thread until
18 // the object has been created.
19 subtle::AtomicWord value;
20 while (true) {
21 value = subtle::NoBarrier_Load(instance);
22 if (value != kBeingCreatedMarker)
23 break;
24 PlatformThread::YieldCurrentThread();
26 return value;
29 } // namespace internal
30 } // namespace base