OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/lazy_instance.h" | 5 #include "base/lazy_instance.h" |
6 | 6 |
7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
9 #include "base/dynamic_annotations.h" | |
10 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
11 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
| 11 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 bool LazyInstanceHelper::NeedsInstance() { | 15 bool LazyInstanceHelper::NeedsInstance() { |
16 // Try to create the instance, if we're the first, will go from EMPTY | 16 // Try to create the instance, if we're the first, will go from EMPTY |
17 // to CREATING, otherwise we've already been beaten here. | 17 // to CREATING, otherwise we've already been beaten here. |
18 if (base::subtle::Acquire_CompareAndSwap( | 18 if (base::subtle::Acquire_CompareAndSwap( |
19 &state_, STATE_EMPTY, STATE_CREATING) == STATE_EMPTY) { | 19 &state_, STATE_EMPTY, STATE_CREATING) == STATE_EMPTY) { |
20 // Caller must create instance | 20 // Caller must create instance |
21 return true; | 21 return true; |
(...skipping 23 matching lines...) Expand all Loading... |
45 // Make sure that the lazily instantiated object will get destroyed at exit. | 45 // Make sure that the lazily instantiated object will get destroyed at exit. |
46 base::AtExitManager::RegisterCallback(dtor, instance); | 46 base::AtExitManager::RegisterCallback(dtor, instance); |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 void LazyInstanceHelper::ResetState(void* helper) { | 50 void LazyInstanceHelper::ResetState(void* helper) { |
51 reinterpret_cast<LazyInstanceHelper*>(helper)->state_ = STATE_EMPTY; | 51 reinterpret_cast<LazyInstanceHelper*>(helper)->state_ = STATE_EMPTY; |
52 } | 52 } |
53 | 53 |
54 } // namespace base | 54 } // namespace base |
OLD | NEW |