[clangd] Synchronize logs access.
I don't think that this is necessary for correctness, but makes tsan
much more useful.
llvm-svn: 295194
diff --git a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
index fd0b394..f3045fb 100644
--- a/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
+++ b/clang-tools-extra/clangd/JSONRPCDispatcher.cpp
@@ -29,8 +29,14 @@
Outs.flush();
}
+void JSONOutput::log(const Twine &Message) {
+ std::lock_guard<std::mutex> Guard(StreamMutex);
+ Logs << Message;
+ Logs.flush();
+}
+
void Handler::handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) {
- Output.logs() << "Method ignored.\n";
+ Output.log("Method ignored.\n");
// Return that this method is unsupported.
writeMessage(
R"({"jsonrpc":"2.0","id":)" + ID +
@@ -38,7 +44,7 @@
}
void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
- Output.logs() << "Notification ignored.\n";
+ Output.log("Notification ignored.\n");
}
void JSONRPCDispatcher::registerHandler(StringRef Method,