aboutsummaryrefslogtreecommitdiff
path: root/lldb/source
diff options
context:
space:
mode:
authorChelsea Cassanova <chelsea_cassanova@apple.com>2024-02-15 15:46:47 -0800
committerGitHub <noreply@github.com>2024-02-15 15:46:47 -0800
commit327d2f8c6cee019d4f915036f40041b5369b61e5 (patch)
tree326530d6c7c6a257563610132ebc95d82f15381a /lldb/source
parent72e14fb33fa8f0c9b08b328367fb3abd1f7d1a49 (diff)
downloadllvm-327d2f8c6cee019d4f915036f40041b5369b61e5.zip
llvm-327d2f8c6cee019d4f915036f40041b5369b61e5.tar.gz
llvm-327d2f8c6cee019d4f915036f40041b5369b61e5.tar.bz2
[lldb][progress] Add progress manager class (#81319)
Per discussions from https://github.com/llvm/llvm-project/pull/81026, it was decided that having a class that manages a map of progress reports would be beneficial in order to categorize them. This class is a part of the overall `Progress` class and utilizes a map that keeps a count of how many times a progress report category has been sent. This would be used with the new debugger broadcast bit added in https://github.com/llvm/llvm-project/pull/81169 so that a user listening with that bit will receive grouped progress reports.
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/Progress.cpp33
1 files changed, 33 insertions, 0 deletions
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;
+}