Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/ClearOnShutdown.h"
8 :
9 : namespace mozilla {
10 : namespace ClearOnShutdown_Internal {
11 :
12 : Array<StaticAutoPtr<ShutdownList>,
13 3 : static_cast<size_t>(ShutdownPhase::ShutdownPhase_Length)> sShutdownObservers;
14 : ShutdownPhase sCurrentShutdownPhase = ShutdownPhase::NotInShutdown;
15 :
16 : } // namespace ClearOnShutdown_Internal
17 :
18 : // Called when XPCOM is shutting down, after all shutdown notifications have
19 : // been sent and after all threads' event loops have been purged.
20 : void
21 0 : KillClearOnShutdown(ShutdownPhase aPhase)
22 : {
23 : using namespace ClearOnShutdown_Internal;
24 :
25 0 : MOZ_ASSERT(NS_IsMainThread());
26 : // Shutdown only goes one direction...
27 0 : MOZ_ASSERT(static_cast<size_t>(sCurrentShutdownPhase) < static_cast<size_t>(aPhase));
28 :
29 : // It's impossible to add an entry for a "past" phase; this is blocked in
30 : // ClearOnShutdown, but clear them out anyways in case there are phases
31 : // that weren't passed to KillClearOnShutdown.
32 0 : for (size_t phase = static_cast<size_t>(ShutdownPhase::First);
33 0 : phase <= static_cast<size_t>(aPhase);
34 : phase++) {
35 0 : if (sShutdownObservers[static_cast<size_t>(phase)]) {
36 0 : while (ShutdownObserver* observer = sShutdownObservers[static_cast<size_t>(phase)]->popFirst()) {
37 0 : observer->Shutdown();
38 0 : delete observer;
39 0 : }
40 0 : sShutdownObservers[static_cast<size_t>(phase)] = nullptr;
41 : }
42 : }
43 0 : }
44 :
45 : } // namespace mozilla
|