Skip to content

Commit 8d36a82

Browse files
committed
[lldb] Flush the global thread pool in Debugger::Terminate
Use the Initialize/Terminate pattern for the global thread pool to make sure it gets flushed during teardown. Differential revision: https://reviews.llvm.org/D131407
1 parent df2213f commit 8d36a82

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lldb/source/Core/Debugger.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ static std::recursive_mutex *g_debugger_list_mutex_ptr =
104104
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
105105
static DebuggerList *g_debugger_list_ptr =
106106
nullptr; // NOTE: intentional leak to avoid issues with C++ destructor chain
107+
static llvm::ThreadPool *g_thread_pool = nullptr;
107108

108109
static constexpr OptionEnumValueElement g_show_disassembly_enum_values[] = {
109110
{
@@ -538,13 +539,19 @@ void Debugger::Initialize(LoadPluginCallbackType load_plugin_callback) {
538539
"Debugger::Initialize called more than once!");
539540
g_debugger_list_mutex_ptr = new std::recursive_mutex();
540541
g_debugger_list_ptr = new DebuggerList();
542+
g_thread_pool = new llvm::ThreadPool(llvm::optimal_concurrency());
541543
g_load_plugin_callback = load_plugin_callback;
542544
}
543545

544546
void Debugger::Terminate() {
545547
assert(g_debugger_list_ptr &&
546548
"Debugger::Terminate called without a matching Debugger::Initialize!");
547549

550+
if (g_thread_pool) {
551+
// The destructor will wait for all the threads to complete.
552+
delete g_thread_pool;
553+
}
554+
548555
if (g_debugger_list_ptr && g_debugger_list_mutex_ptr) {
549556
// Clear our global list of debugger objects
550557
{
@@ -2005,11 +2012,7 @@ Status Debugger::RunREPL(LanguageType language, const char *repl_options) {
20052012
}
20062013

20072014
llvm::ThreadPool &Debugger::GetThreadPool() {
2008-
// NOTE: intentional leak to avoid issues with C++ destructor chain
2009-
static llvm::ThreadPool *g_thread_pool = nullptr;
2010-
static llvm::once_flag g_once_flag;
2011-
llvm::call_once(g_once_flag, []() {
2012-
g_thread_pool = new llvm::ThreadPool(llvm::optimal_concurrency());
2013-
});
2015+
assert(g_thread_pool &&
2016+
"Debugger::GetThreadPool called before Debugger::Initialize");
20142017
return *g_thread_pool;
20152018
}

0 commit comments

Comments
 (0)