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

Side by Side Diff: base/lazy_instance.cc

Issue 147008: Added dynamic annotation files into base/...,... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/lazy_instance.h ('k') | base/singleton.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/platform_thread.h" 11 #include "base/platform_thread.h"
11 12
12 namespace base { 13 namespace base {
13 14
14 void LazyInstanceHelper::EnsureInstance(void* instance, 15 void LazyInstanceHelper::EnsureInstance(void* instance,
15 void (*ctor)(void*), 16 void (*ctor)(void*),
16 void (*dtor)(void*)) { 17 void (*dtor)(void*)) {
17 // Try to create the instance, if we're the first, will go from EMPTY 18 // Try to create the instance, if we're the first, will go from EMPTY
18 // to CREATING, otherwise we've already been beaten here. 19 // to CREATING, otherwise we've already been beaten here.
19 if (base::subtle::Acquire_CompareAndSwap( 20 if (base::subtle::Acquire_CompareAndSwap(
20 &state_, STATE_EMPTY, STATE_CREATING) == STATE_EMPTY) { 21 &state_, STATE_EMPTY, STATE_CREATING) == STATE_EMPTY) {
21 // Created the instance in the space provided by |instance|. 22 // Created the instance in the space provided by |instance|.
22 ctor(instance); 23 ctor(instance);
24
25 // See the comment to the corresponding HAPPENS_AFTER in Pointer().
26 ANNOTATE_HAPPENS_BEFORE(&state_);
27
23 // Instance is created, go from CREATING to CREATED. 28 // Instance is created, go from CREATING to CREATED.
24 base::subtle::Release_Store(&state_, STATE_CREATED); 29 base::subtle::Release_Store(&state_, STATE_CREATED);
25 // Register the destructor callback with AtExitManager. 30 // Register the destructor callback with AtExitManager.
26 base::AtExitManager::RegisterCallback(dtor, instance); 31 base::AtExitManager::RegisterCallback(dtor, instance);
27 } else { 32 } else {
28 // It's either in the process of being created, or already created. Spin. 33 // It's either in the process of being created, or already created. Spin.
29 while (base::subtle::NoBarrier_Load(&state_) != STATE_CREATED) 34 while (base::subtle::NoBarrier_Load(&state_) != STATE_CREATED)
30 PlatformThread::YieldCurrentThread(); 35 PlatformThread::YieldCurrentThread();
31 } 36 }
32 } 37 }
33 38
34 } // namespace base 39 } // namespace base
OLDNEW
« no previous file with comments | « base/lazy_instance.h ('k') | base/singleton.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698