Index: lldb/include/lldb/Core/Debugger.h =================================================================== --- lldb/include/lldb/Core/Debugger.h +++ lldb/include/lldb/Core/Debugger.h @@ -49,6 +49,7 @@ namespace llvm { class raw_ostream; +class ThreadPool; } namespace lldb_private { @@ -379,6 +380,9 @@ return m_broadcaster_manager_sp; } + /// Shared thread poll. Use only with ThreadPoolTaskGroup. + static llvm::ThreadPool &GetThreadPool(); + /// Report warning events. /// /// Progress events will be delivered to any debuggers that have listeners Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -66,6 +66,7 @@ #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" +#include "llvm/Support/ThreadPool.h" #include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" @@ -96,6 +97,7 @@ static lldb::user_id_t g_unique_id = 1; static size_t g_debugger_event_thread_stack_bytes = 8 * 1024 * 1024; +static std::unique_ptr g_threadpool; #pragma mark Static Functions @@ -756,6 +758,7 @@ GetStaticBroadcasterClass().AsCString()), m_forward_listener_sp(), m_clear_once() { m_instance_name.SetString(llvm::formatv("debugger_{0}", GetID()).str()); + g_threadpool = std::make_unique(llvm::optimal_concurrency()); if (log_callback) m_log_callback_stream_sp = std::make_shared(log_callback, baton); @@ -846,6 +849,7 @@ GetInputFile().Close(); m_command_interpreter_up->Clear(); + g_threadpool.reset(); }); } @@ -1970,3 +1974,8 @@ return err; } + +llvm::ThreadPool &Debugger::GetThreadPool() { + assert(g_threadpool); + return *g_threadpool; +} Index: lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.cpp @@ -13,6 +13,7 @@ #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h" #include "lldb/Core/DataFileCache.h" +#include "lldb/Core/Debugger.h" #include "lldb/Core/Module.h" #include "lldb/Core/Progress.h" #include "lldb/Symbol/ObjectFile.h" @@ -94,7 +95,7 @@ // Share one thread pool across operations to avoid the overhead of // recreating the threads. - llvm::ThreadPool pool(llvm::optimal_concurrency(units_to_index.size())); + llvm::ThreadPoolTaskGroup task_group(Debugger::GetThreadPool()); // Create a task runner that extracts dies for each DWARF unit in a // separate thread. @@ -105,14 +106,14 @@ // to wait until all units have been indexed in case a DIE in one // unit refers to another and the indexes accesses those DIEs. for (size_t i = 0; i < units_to_index.size(); ++i) - pool.async(extract_fn, i); - pool.wait(); + task_group.async(extract_fn, i); + task_group.wait(); // Now create a task runner that can index each DWARF unit in a // separate thread so we can index quickly. for (size_t i = 0; i < units_to_index.size(); ++i) - pool.async(parser_fn, i); - pool.wait(); + task_group.async(parser_fn, i); + task_group.wait(); auto finalize_fn = [this, &sets, &progress](NameToDIE(IndexSet::*index)) { NameToDIE &result = m_set.*index; @@ -122,15 +123,15 @@ progress.Increment(); }; - pool.async(finalize_fn, &IndexSet::function_basenames); - pool.async(finalize_fn, &IndexSet::function_fullnames); - pool.async(finalize_fn, &IndexSet::function_methods); - pool.async(finalize_fn, &IndexSet::function_selectors); - pool.async(finalize_fn, &IndexSet::objc_class_selectors); - pool.async(finalize_fn, &IndexSet::globals); - pool.async(finalize_fn, &IndexSet::types); - pool.async(finalize_fn, &IndexSet::namespaces); - pool.wait(); + task_group.async(finalize_fn, &IndexSet::function_basenames); + task_group.async(finalize_fn, &IndexSet::function_fullnames); + task_group.async(finalize_fn, &IndexSet::function_methods); + task_group.async(finalize_fn, &IndexSet::function_selectors); + task_group.async(finalize_fn, &IndexSet::objc_class_selectors); + task_group.async(finalize_fn, &IndexSet::globals); + task_group.async(finalize_fn, &IndexSet::types); + task_group.async(finalize_fn, &IndexSet::namespaces); + task_group.wait(); SaveToCache(); }