[clang-tools-extra] r295194 - [clangd] Synchronize logs access.

Benjamin Kramer via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 15 08:44:12 PST 2017


Author: d0k
Date: Wed Feb 15 10:44:11 2017
New Revision: 295194

URL: http://llvm.org/viewvc/llvm-project?rev=295194&view=rev
Log:
[clangd] Synchronize logs access.

I don't think that this is necessary for correctness, but makes tsan
much more useful.

Modified:
    clang-tools-extra/trunk/clangd/ASTManager.cpp
    clang-tools-extra/trunk/clangd/ClangDMain.cpp
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
    clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
    clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp

Modified: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=295194&r1=295193&r2=295194&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Wed Feb 15 10:44:11 2017
@@ -150,7 +150,7 @@ ASTManager::getOrCreateCompilationDataba
 
   std::string Error;
   I = tooling::CompilationDatabase::autoDetectFromSource(Uri, Error);
-  Output.logs() << "Failed to load compilation database: " << Error << '\n';
+  Output.log("Failed to load compilation database: " + Twine(Error) + "\n");
   return I.get();
 }
 

Modified: clang-tools-extra/trunk/clangd/ClangDMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangDMain.cpp?rev=295194&r1=295193&r2=295194&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ClangDMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangDMain.cpp Wed Feb 15 10:44:11 2017
@@ -88,12 +88,11 @@ int main(int argc, char *argv[]) {
     if (Len > 0) {
       llvm::StringRef JSONRef(JSON.data(), Len);
       // Log the message.
-      Logs << "<-- " << JSONRef << '\n';
-      Logs.flush();
+      Out.log("<-- " + JSONRef + "\n");
 
       // Finally, execute the action for this JSON message.
       if (!Dispatcher.call(JSONRef))
-        Logs << "JSON dispatch failed!\n";
+        Out.log("JSON dispatch failed!\n");
 
       // If we're done, exit the loop.
       if (ShutdownHandler->isDone())

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=295194&r1=295193&r2=295194&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Wed Feb 15 10:44:11 2017
@@ -29,8 +29,14 @@ void JSONOutput::writeMessage(const Twin
   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::handleMethod(llvm::yaml::M
 }
 
 void Handler::handleNotification(llvm::yaml::MappingNode *Params) {
-  Output.logs() << "Notification ignored.\n";
+  Output.log("Notification ignored.\n");
 }
 
 void JSONRPCDispatcher::registerHandler(StringRef Method,

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=295194&r1=295193&r2=295194&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Wed Feb 15 10:44:11 2017
@@ -28,8 +28,8 @@ public:
   /// Emit a JSONRPC message.
   void writeMessage(const Twine &Message);
 
-  /// Get the logging stream.
-  llvm::raw_ostream &logs() { return Logs; }
+  /// Write to the logging stream.
+  void log(const Twine &Message);
 
 private:
   llvm::raw_ostream &Outs;

Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp?rev=295194&r1=295193&r2=295194&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp (original)
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp Wed Feb 15 10:44:11 2017
@@ -17,7 +17,7 @@ void TextDocumentDidOpenHandler::handleN
     llvm::yaml::MappingNode *Params) {
   auto DOTDP = DidOpenTextDocumentParams::parse(Params);
   if (!DOTDP) {
-    Output.logs() << "Failed to decode DidOpenTextDocumentParams!\n";
+    Output.log("Failed to decode DidOpenTextDocumentParams!\n");
     return;
   }
   Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
@@ -27,7 +27,7 @@ void TextDocumentDidChangeHandler::handl
     llvm::yaml::MappingNode *Params) {
   auto DCTDP = DidChangeTextDocumentParams::parse(Params);
   if (!DCTDP || DCTDP->contentChanges.size() != 1) {
-    Output.logs() << "Failed to decode DidChangeTextDocumentParams!\n";
+    Output.log("Failed to decode DidChangeTextDocumentParams!\n");
     return;
   }
   // We only support full syncing right now.
@@ -91,7 +91,7 @@ void TextDocumentRangeFormattingHandler:
     llvm::yaml::MappingNode *Params, StringRef ID) {
   auto DRFP = DocumentRangeFormattingParams::parse(Params);
   if (!DRFP) {
-    Output.logs() << "Failed to decode DocumentRangeFormattingParams!\n";
+    Output.log("Failed to decode DocumentRangeFormattingParams!\n");
     return;
   }
 
@@ -108,7 +108,7 @@ void TextDocumentFormattingHandler::hand
     llvm::yaml::MappingNode *Params, StringRef ID) {
   auto DFP = DocumentFormattingParams::parse(Params);
   if (!DFP) {
-    Output.logs() << "Failed to decode DocumentFormattingParams!\n";
+    Output.log("Failed to decode DocumentFormattingParams!\n");
     return;
   }
 




More information about the cfe-commits mailing list