llvm-capstone/lldb/source/Initialization/SystemLifetimeManager.cpp
Zachary Turner e6e2bb3842 Rework LLDB system initialization.
In an effort to reduce binary size for components not wishing to
link against all of LLDB, as well as a parallel effort to reduce
link dependencies on Python, this patch splits out the notion of
LLDB initialization into "full" and "common" initialization.

All code related to initializing the full LLDB suite lives directly
in API now.  Previously it was only referenced from API, but because
it was defined in lldbCore, it would get implicitly linked against
by everything including lldb-server, causing a considerable
increase in binary size.

By moving this to the API layer, it also creates a better layering
for the ongoing effort to make the embedded interpreter replacable
with one from a different language (or even be completely removeable).

One semantic change necessary to get this all working was to remove
the notion of a shared debugger refcount.  The debugger is either
initialized or uninitialized now, and calling Initialize() multiple
times will simply have no effect, while the first Terminate() will
now shut it down no matter how many times Initialize() was called.
This behaves nicely with all of our supported usage patterns though,
and allows us to fix a number of nasty hacks from before.

Differential Revision: http://reviews.llvm.org/D8462

llvm-svn: 233758
2015-03-31 21:03:22 +00:00

62 lines
1.6 KiB
C++

//===-- SystemLifetimeManager.cpp ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Host/Mutex.h"
#include "lldb/Initialization/SystemInitializer.h"
#include <utility>
using namespace lldb_private;
SystemLifetimeManager::SystemLifetimeManager()
: m_mutex(Mutex::eMutexTypeRecursive)
, m_initialized(false)
{
}
SystemLifetimeManager::~SystemLifetimeManager()
{
assert(!m_initialized && "SystemLifetimeManager destroyed without calling Terminate!");
}
void
SystemLifetimeManager::Initialize(std::unique_ptr<SystemInitializer> initializer,
LoadPluginCallbackType plugin_callback)
{
Mutex::Locker locker(m_mutex);
if (!m_initialized)
{
assert(!m_initializer &&
"Attempting to call SystemLifetimeManager::Initialize() when it is already initialized");
m_initialized = true;
m_initializer = std::move(initializer);
m_initializer->Initialize();
Debugger::Initialize(plugin_callback);
}
}
void
SystemLifetimeManager::Terminate()
{
Mutex::Locker locker(m_mutex);
if (m_initialized)
{
Debugger::Terminate();
m_initializer->Terminate();
m_initializer.reset();
m_initialized = false;
}
}