1 //===-- SystemLifetimeManager.cpp -----------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Initialization/SystemLifetimeManager.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Initialization/SystemInitializer.h"
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
);
30 assert(!m_initializer
&& "Attempting to call "
31 "SystemLifetimeManager::Initialize() when it is "
32 "already initialized");
34 m_initializer
= std::move(initializer
);
36 if (auto e
= m_initializer
->Initialize())
39 Debugger::Initialize(plugin_callback
);
42 return llvm::Error::success();
45 void SystemLifetimeManager::Terminate() {
46 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
49 Debugger::Terminate();
50 m_initializer
->Terminate();
52 m_initializer
.reset();
53 m_initialized
= false;