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 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Initialization/SystemLifetimeManager.h" 10 11 #include "lldb/Core/Debugger.h" 12 #include "lldb/Initialization/SystemInitializer.h" 13 14 #include <utility> 15 16 using namespace lldb_private; 17 SystemLifetimeManager()18SystemLifetimeManager::SystemLifetimeManager() 19 : m_mutex(), m_initialized(false) {} 20 ~SystemLifetimeManager()21SystemLifetimeManager::~SystemLifetimeManager() { 22 assert(!m_initialized && 23 "SystemLifetimeManager destroyed without calling Terminate!"); 24 } 25 Initialize(std::unique_ptr<SystemInitializer> initializer,LoadPluginCallbackType plugin_callback)26llvm::Error SystemLifetimeManager::Initialize( 27 std::unique_ptr<SystemInitializer> initializer, 28 LoadPluginCallbackType plugin_callback) { 29 std::lock_guard<std::recursive_mutex> guard(m_mutex); 30 if (!m_initialized) { 31 assert(!m_initializer && "Attempting to call " 32 "SystemLifetimeManager::Initialize() when it is " 33 "already initialized"); 34 m_initialized = true; 35 m_initializer = std::move(initializer); 36 37 if (auto e = m_initializer->Initialize()) 38 return e; 39 40 Debugger::Initialize(plugin_callback); 41 } 42 43 return llvm::Error::success(); 44 } 45 Terminate()46void SystemLifetimeManager::Terminate() { 47 std::lock_guard<std::recursive_mutex> guard(m_mutex); 48 49 if (m_initialized) { 50 Debugger::Terminate(); 51 m_initializer->Terminate(); 52 53 m_initializer.reset(); 54 m_initialized = false; 55 } 56 } 57