OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/at_exit.h" | 5 #include "base/at_exit.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 // Keep a stack of registered AtExitManagers. We always operate on the most | 14 // Keep a stack of registered AtExitManagers. We always operate on the most |
15 // recent, and we should never have more than one outside of testing (for a | 15 // recent, and we should never have more than one outside of testing (for a |
16 // statically linked version of this library). Testing may use the shadow | 16 // statically linked version of this library). Testing may use the shadow |
17 // version of the constructor, and if we are building a dynamic library we may | 17 // version of the constructor, and if we are building a dynamic library we may |
18 // end up with multiple AtExitManagers on the same process. We don't protect | 18 // end up with multiple AtExitManagers on the same process. We don't protect |
19 // this for thread-safe access, since it will only be modified in testing. | 19 // this for thread-safe access, since it will only be modified in testing. |
20 static AtExitManager* g_top_manager = NULL; | 20 static AtExitManager* g_top_manager = NULL; |
21 | 21 |
22 AtExitManager::AtExitManager() : next_manager_(g_top_manager) { | 22 AtExitManager::AtExitManager() : next_manager_(g_top_manager) { |
23 // If multiple modules instantiate AtExitManagers they'll end up living in this | 23 // If multiple modules instantiate AtExitManagers they'll end up living in this |
24 // module... they have to coexist. | 24 // module... they have to coexist. |
25 #if !defined(BASE_DLL) | 25 #if !defined(COMPONENT_BUILD) |
26 DCHECK(!g_top_manager); | 26 DCHECK(!g_top_manager); |
27 #endif | 27 #endif |
28 g_top_manager = this; | 28 g_top_manager = this; |
29 } | 29 } |
30 | 30 |
31 AtExitManager::~AtExitManager() { | 31 AtExitManager::~AtExitManager() { |
32 if (!g_top_manager) { | 32 if (!g_top_manager) { |
33 NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager"; | 33 NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager"; |
34 return; | 34 return; |
35 } | 35 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 callback_and_param.func_(callback_and_param.param_); | 68 callback_and_param.func_(callback_and_param.param_); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 AtExitManager::AtExitManager(bool shadow) : next_manager_(g_top_manager) { | 72 AtExitManager::AtExitManager(bool shadow) : next_manager_(g_top_manager) { |
73 DCHECK(shadow || !g_top_manager); | 73 DCHECK(shadow || !g_top_manager); |
74 g_top_manager = this; | 74 g_top_manager = this; |
75 } | 75 } |
76 | 76 |
77 } // namespace base | 77 } // namespace base |
OLD | NEW |