Author: d0k Date: Fri Feb 10 11:25:38 2017 New Revision: 294760 URL: http://llvm.org/viewvc/llvm-project?rev=294760&view=rev Log: [clangd] Move isDone from the JSONOutput to ShutdownHandler.
This is just as easy to check from main but prevents random code from shutting down the server. Modified: clang-tools-extra/trunk/clangd/ClangDMain.cpp clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h clang-tools-extra/trunk/clangd/ProtocolHandlers.h Modified: clang-tools-extra/trunk/clangd/ClangDMain.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangDMain.cpp?rev=294760&r1=294759&r2=294760&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangDMain.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangDMain.cpp Fri Feb 10 11:25:38 2017 @@ -30,8 +30,9 @@ int main(int argc, char *argv[]) { JSONRPCDispatcher Dispatcher(llvm::make_unique<Handler>(Out)); Dispatcher.registerHandler("initialize", llvm::make_unique<InitializeHandler>(Out)); - Dispatcher.registerHandler("shutdown", - llvm::make_unique<ShutdownHandler>(Out)); + auto ShutdownPtr = llvm::make_unique<ShutdownHandler>(Out); + auto *ShutdownHandler = ShutdownPtr.get(); + Dispatcher.registerHandler("shutdown",std::move(ShutdownPtr)); Dispatcher.registerHandler( "textDocument/didOpen", llvm::make_unique<TextDocumentDidOpenHandler>(Out, Store)); @@ -92,7 +93,7 @@ int main(int argc, char *argv[]) { Logs << "JSON dispatch failed!\n"; // If we're done, exit the loop. - if (Out.isDone()) + if (ShutdownHandler->isDone()) break; } } Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h?rev=294760&r1=294759&r2=294760&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h (original) +++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h Fri Feb 10 11:25:38 2017 @@ -31,17 +31,10 @@ public: /// Get the logging stream. llvm::raw_ostream &logs() { return Logs; } - /// Use this to indicate that the output stream should be closed and the - /// process should terminate. - void setDone() { Done = true; } - bool isDone() const { return Done; } - private: llvm::raw_ostream &Outs; llvm::raw_ostream &Logs; - bool Done = false; - std::mutex StreamMutex; }; Modified: clang-tools-extra/trunk/clangd/ProtocolHandlers.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ProtocolHandlers.h?rev=294760&r1=294759&r2=294760&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ProtocolHandlers.h (original) +++ clang-tools-extra/trunk/clangd/ProtocolHandlers.h Fri Feb 10 11:25:38 2017 @@ -42,8 +42,13 @@ struct ShutdownHandler : Handler { ShutdownHandler(JSONOutput &Output) : Handler(Output) {} void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override { - Output.setDone(); + IsDone = true; } + + bool isDone() const { return IsDone; } + +private: + bool IsDone = false; }; struct TextDocumentDidOpenHandler : Handler { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits