Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Initialization / SystemLifetimeManager.cpp
blobf9de41a6753560d58434065402a8cca65f9c338a
1 //===-- SystemLifetimeManager.cpp -----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Initialization/SystemLifetimeManager.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Initialization/SystemInitializer.h"
14 #include <utility>
16 using namespace lldb_private;
18 SystemLifetimeManager::SystemLifetimeManager() : m_mutex() {}
20 SystemLifetimeManager::~SystemLifetimeManager() {
21 assert(!m_initialized &&
22 "SystemLifetimeManager destroyed without calling Terminate!");
25 llvm::Error SystemLifetimeManager::Initialize(
26 std::unique_ptr<SystemInitializer> initializer,
27 LoadPluginCallbackType plugin_callback) {
28 std::lock_guard<std::recursive_mutex> guard(m_mutex);
29 if (!m_initialized) {
30 assert(!m_initializer && "Attempting to call "
31 "SystemLifetimeManager::Initialize() when it is "
32 "already initialized");
33 m_initialized = true;
34 m_initializer = std::move(initializer);
36 if (auto e = m_initializer->Initialize())
37 return e;
39 Debugger::Initialize(plugin_callback);
42 return llvm::Error::success();
45 void SystemLifetimeManager::Terminate() {
46 std::lock_guard<std::recursive_mutex> guard(m_mutex);
48 if (m_initialized) {
49 Debugger::Terminate();
50 m_initializer->Terminate();
52 m_initializer.reset();
53 m_initialized = false;