summaryrefslogtreecommitdiff
path: root/lldb/source/Core/ProtocolServer.cpp
diff options
context:
space:
mode:
authorMingming Liu <mingmingl@google.com>2025-09-10 15:25:31 -0700
committerGitHub <noreply@github.com>2025-09-10 15:25:31 -0700
commit1417dafa1db9cb1b2b09438aa9f53ea5ab6e36e2 (patch)
tree57f4b1f313c8cf74eed8819870f39c36ea263c68 /lldb/source/Core/ProtocolServer.cpp
parent898b813bc8a6d0276bf0f4769f5f2f64b34e632d (diff)
parentb8cefcb601ddaa18482555c4ff363c01a270c2fe (diff)
Merge branch 'main' into users/mingmingl-llvm/samplefdo-profile-formatusers/mingmingl-llvm/samplefdo-profile-format
Diffstat (limited to 'lldb/source/Core/ProtocolServer.cpp')
-rw-r--r--lldb/source/Core/ProtocolServer.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/lldb/source/Core/ProtocolServer.cpp b/lldb/source/Core/ProtocolServer.cpp
index 41636cdacdec..38668f39795a 100644
--- a/lldb/source/Core/ProtocolServer.cpp
+++ b/lldb/source/Core/ProtocolServer.cpp
@@ -8,24 +8,29 @@
#include "lldb/Core/ProtocolServer.h"
#include "lldb/Core/PluginManager.h"
+#include "llvm/Support/Error.h"
using namespace lldb_private;
using namespace lldb;
-ProtocolServer *ProtocolServer::GetOrCreate(llvm::StringRef name) {
- static std::mutex g_mutex;
+static std::pair<llvm::StringMap<ProtocolServerUP> &, std::mutex &> Servers() {
static llvm::StringMap<ProtocolServerUP> g_protocol_server_instances;
+ static std::mutex g_mutex;
+ return {g_protocol_server_instances, g_mutex};
+}
+
+ProtocolServer *ProtocolServer::GetOrCreate(llvm::StringRef name) {
+ auto [protocol_server_instances, mutex] = Servers();
- std::lock_guard<std::mutex> guard(g_mutex);
+ std::lock_guard<std::mutex> guard(mutex);
- auto it = g_protocol_server_instances.find(name);
- if (it != g_protocol_server_instances.end())
+ auto it = protocol_server_instances.find(name);
+ if (it != protocol_server_instances.end())
return it->second.get();
if (ProtocolServerCreateInstance create_callback =
PluginManager::GetProtocolCreateCallbackForPluginName(name)) {
- auto pair =
- g_protocol_server_instances.try_emplace(name, create_callback());
+ auto pair = protocol_server_instances.try_emplace(name, create_callback());
return pair.first->second.get();
}
@@ -45,3 +50,18 @@ std::vector<llvm::StringRef> ProtocolServer::GetSupportedProtocols() {
return supported_protocols;
}
+
+llvm::Error ProtocolServer::Terminate() {
+ llvm::Error error = llvm::Error::success();
+
+ auto [protocol_server_instances, mutex] = Servers();
+ std::lock_guard<std::mutex> guard(mutex);
+ for (auto &instance : protocol_server_instances) {
+ if (llvm::Error instance_error = instance.second->Stop())
+ error = llvm::joinErrors(std::move(error), std::move(instance_error));
+ }
+
+ protocol_server_instances.clear();
+
+ return error;
+}