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

Side by Side Diff: base/at_exit.cc

Issue 2309153002: Remove RenderThreadImpl::Shutdown (Closed)
Patch Set: temp Created 3 years, 11 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
« no previous file with comments | « base/at_exit.h ('k') | content/child/child_process.cc » ('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) 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 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 // Keep a stack of registered AtExitManagers. We always operate on the most 17 // Keep a stack of registered AtExitManagers. We always operate on the most
18 // recent, and we should never have more than one outside of testing (for a 18 // recent, and we should never have more than one outside of testing (for a
19 // statically linked version of this library). Testing may use the shadow 19 // statically linked version of this library). Testing may use the shadow
20 // version of the constructor, and if we are building a dynamic library we may 20 // version of the constructor, and if we are building a dynamic library we may
21 // end up with multiple AtExitManagers on the same process. We don't protect 21 // end up with multiple AtExitManagers on the same process. We don't protect
22 // this for thread-safe access, since it will only be modified in testing. 22 // this for thread-safe access, since it will only be modified in testing.
23 static AtExitManager* g_top_manager = NULL; 23 static AtExitManager* g_top_manager = NULL;
24 24
25 static bool g_disable_managers = false;
26
25 AtExitManager::AtExitManager() 27 AtExitManager::AtExitManager()
26 : processing_callbacks_(false), next_manager_(g_top_manager) { 28 : processing_callbacks_(false), next_manager_(g_top_manager) {
27 // If multiple modules instantiate AtExitManagers they'll end up living in this 29 // If multiple modules instantiate AtExitManagers they'll end up living in this
28 // module... they have to coexist. 30 // module... they have to coexist.
29 #if !defined(COMPONENT_BUILD) 31 #if !defined(COMPONENT_BUILD)
30 DCHECK(!g_top_manager); 32 DCHECK(!g_top_manager);
31 #endif 33 #endif
32 g_top_manager = this; 34 g_top_manager = this;
33 } 35 }
34 36
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // handle it gracefully in release builds so we don't deadlock. 75 // handle it gracefully in release builds so we don't deadlock.
74 std::stack<base::Closure> tasks; 76 std::stack<base::Closure> tasks;
75 { 77 {
76 AutoLock lock(g_top_manager->lock_); 78 AutoLock lock(g_top_manager->lock_);
77 tasks.swap(g_top_manager->stack_); 79 tasks.swap(g_top_manager->stack_);
78 g_top_manager->processing_callbacks_ = true; 80 g_top_manager->processing_callbacks_ = true;
79 } 81 }
80 82
81 while (!tasks.empty()) { 83 while (!tasks.empty()) {
82 base::Closure task = tasks.top(); 84 base::Closure task = tasks.top();
83 task.Run(); 85 if (!g_disable_managers)
dcheng 2017/01/12 02:22:38 Is it important to pop the tasks like this? I wond
haraken 2017/01/12 02:44:02 Fixed.
86 task.Run();
84 tasks.pop(); 87 tasks.pop();
85 } 88 }
86 89
87 // Expect that all callbacks have been run. 90 // Expect that all callbacks have been run.
88 DCHECK(g_top_manager->stack_.empty()); 91 DCHECK(g_top_manager->stack_.empty());
89 } 92 }
90 93
94 void AtExitManager::DisableAllAtExitManagers() {
95 AutoLock lock(g_top_manager->lock_);
96 g_disable_managers = true;
97 }
98
91 AtExitManager::AtExitManager(bool shadow) 99 AtExitManager::AtExitManager(bool shadow)
92 : processing_callbacks_(false), next_manager_(g_top_manager) { 100 : processing_callbacks_(false), next_manager_(g_top_manager) {
93 DCHECK(shadow || !g_top_manager); 101 DCHECK(shadow || !g_top_manager);
94 g_top_manager = this; 102 g_top_manager = this;
95 } 103 }
96 104
97 } // namespace base 105 } // namespace base
OLDNEW
« no previous file with comments | « base/at_exit.h ('k') | content/child/child_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698