OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 | 7 |
8 namespace base { | 8 namespace base { |
9 | 9 |
10 // Keep a stack of registered AtExitManagers. We always operate on the most | 10 // Keep a stack of registered AtExitManagers. We always operate on the most |
(...skipping 17 matching lines...) Expand all Loading... |
28 NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager"; | 28 NOTREACHED() << "Tried to ~AtExitManager without an AtExitManager"; |
29 return; | 29 return; |
30 } | 30 } |
31 DCHECK(g_top_manager == this); | 31 DCHECK(g_top_manager == this); |
32 | 32 |
33 ProcessCallbacksNow(); | 33 ProcessCallbacksNow(); |
34 g_top_manager = next_manager_; | 34 g_top_manager = next_manager_; |
35 } | 35 } |
36 | 36 |
37 // static | 37 // static |
38 void AtExitManager::RegisterCallback(AtExitCallbackType func) { | 38 void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) { |
39 if (!g_top_manager) { | 39 if (!g_top_manager) { |
40 NOTREACHED() << "Tried to RegisterCallback without an AtExitManager"; | 40 NOTREACHED() << "Tried to RegisterCallback without an AtExitManager"; |
41 return; | 41 return; |
42 } | 42 } |
43 | 43 |
| 44 DCHECK(func); |
| 45 |
44 AutoLock lock(g_top_manager->lock_); | 46 AutoLock lock(g_top_manager->lock_); |
45 g_top_manager->stack_.push(func); | 47 g_top_manager->stack_.push(CallbackAndParam(func, param)); |
46 } | 48 } |
47 | 49 |
48 // static | 50 // static |
49 void AtExitManager::ProcessCallbacksNow() { | 51 void AtExitManager::ProcessCallbacksNow() { |
50 if (!g_top_manager) { | 52 if (!g_top_manager) { |
51 NOTREACHED() << "Tried to ProcessCallbacksNow without an AtExitManager"; | 53 NOTREACHED() << "Tried to ProcessCallbacksNow without an AtExitManager"; |
52 return; | 54 return; |
53 } | 55 } |
54 | 56 |
55 AutoLock lock(g_top_manager->lock_); | 57 AutoLock lock(g_top_manager->lock_); |
56 | 58 |
57 while (!g_top_manager->stack_.empty()) { | 59 while (!g_top_manager->stack_.empty()) { |
58 AtExitCallbackType func = g_top_manager->stack_.top(); | 60 CallbackAndParam callback_and_param = g_top_manager->stack_.top(); |
59 g_top_manager->stack_.pop(); | 61 g_top_manager->stack_.pop(); |
60 if (func) | 62 |
61 func(); | 63 callback_and_param.func_(callback_and_param.param_); |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 } // namespace base | 67 } // namespace base |
66 | |
OLD | NEW |