diff options
-rw-r--r-- | lldb/include/lldb/Core/Progress.h | 21 | ||||
-rw-r--r-- | lldb/source/Core/Progress.cpp | 33 |
2 files changed, 54 insertions, 0 deletions
diff --git a/lldb/include/lldb/Core/Progress.h b/lldb/include/lldb/Core/Progress.h index 5d88291..eb4d9f9 100644 --- a/lldb/include/lldb/Core/Progress.h +++ b/lldb/include/lldb/Core/Progress.h @@ -11,6 +11,7 @@ #include "lldb/Utility/ConstString.h" #include "lldb/lldb-types.h" +#include "llvm/ADT/StringMap.h" #include <atomic> #include <mutex> #include <optional> @@ -119,6 +120,26 @@ private: bool m_complete = false; }; +/// A class used to group progress reports by category. This is done by using a +/// map that maintains a refcount of each category of progress reports that have +/// come in. Keeping track of progress reports this way will be done if a +/// debugger is listening to the eBroadcastBitProgressByCategory broadcast bit. +class ProgressManager { +public: + ProgressManager(); + ~ProgressManager(); + + /// Control the refcount of the progress report category as needed. + void Increment(std::string category); + void Decrement(std::string category); + + static ProgressManager &Instance(); + +private: + llvm::StringMap<uint64_t> m_progress_category_map; + std::mutex m_progress_map_mutex; +}; + } // namespace lldb_private #endif // LLDB_CORE_PROGRESS_H diff --git a/lldb/source/Core/Progress.cpp b/lldb/source/Core/Progress.cpp index 732efbc..9e8deb1a 100644 --- a/lldb/source/Core/Progress.cpp +++ b/lldb/source/Core/Progress.cpp @@ -11,6 +11,7 @@ #include "lldb/Core/Debugger.h" #include "lldb/Utility/StreamString.h" +#include <mutex> #include <optional> using namespace lldb; @@ -66,3 +67,35 @@ void Progress::ReportProgress() { m_debugger_id); } } + +ProgressManager::ProgressManager() : m_progress_category_map() {} + +ProgressManager::~ProgressManager() {} + +ProgressManager &ProgressManager::Instance() { + static std::once_flag g_once_flag; + static ProgressManager *g_progress_manager = nullptr; + std::call_once(g_once_flag, []() { + // NOTE: known leak to avoid global destructor chain issues. + g_progress_manager = new ProgressManager(); + }); + return *g_progress_manager; +} + +void ProgressManager::Increment(std::string title) { + std::lock_guard<std::mutex> lock(m_progress_map_mutex); + m_progress_category_map[title]++; +} + +void ProgressManager::Decrement(std::string title) { + std::lock_guard<std::mutex> lock(m_progress_map_mutex); + auto pos = m_progress_category_map.find(title); + + if (pos == m_progress_category_map.end()) + return; + + if (pos->second <= 1) + m_progress_category_map.erase(title); + else + --pos->second; +} |