From 98a1fd7f96cdabfff1c0b9b5448423f3cf2ac1d5 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Tue, 10 Oct 2017 16:12:54 +0000 Subject: [clangd] Use UniqueFunction for deferred computations. Previsouly, `std::future` that were results of `std::async(std::launch::deferred, ...` were used. llvm-svn: 315325 --- clang-tools-extra/clangd/ClangdUnit.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'clang-tools-extra/clangd/ClangdUnit.cpp') diff --git a/clang-tools-extra/clangd/ClangdUnit.cpp b/clang-tools-extra/clangd/ClangdUnit.cpp index ccf0283a294..a476eeb72e2 100644 --- a/clang-tools-extra/clangd/ClangdUnit.cpp +++ b/clang-tools-extra/clangd/ClangdUnit.cpp @@ -1121,9 +1121,9 @@ CppFile::CppFile(PathRef FileName, tooling::CompileCommand Command, ASTFuture = ASTPromise.get_future(); } -void CppFile::cancelRebuild() { deferCancelRebuild().get(); } +void CppFile::cancelRebuild() { deferCancelRebuild()(); } -std::future CppFile::deferCancelRebuild() { +UniqueFunction CppFile::deferCancelRebuild() { std::unique_lock Lock(Mutex); // Cancel an ongoing rebuild, if any, and wait for it to finish. unsigned RequestRebuildCounter = ++this->RebuildCounter; @@ -1143,7 +1143,7 @@ std::future CppFile::deferCancelRebuild() { RebuildCond.notify_all(); std::shared_ptr That = shared_from_this(); - return std::async(std::launch::deferred, [That, RequestRebuildCounter]() { + return [That, RequestRebuildCounter]() { std::unique_lock Lock(That->Mutex); CppFile *This = &*That; This->RebuildCond.wait(Lock, [This, RequestRebuildCounter]() { @@ -1158,16 +1158,16 @@ std::future CppFile::deferCancelRebuild() { // Set empty results for Promises. That->PreamblePromise.set_value(nullptr); That->ASTPromise.set_value(std::make_shared(llvm::None)); - }); + }; } llvm::Optional> CppFile::rebuild(StringRef NewContents, IntrusiveRefCntPtr VFS) { - return deferRebuild(NewContents, std::move(VFS)).get(); + return deferRebuild(NewContents, std::move(VFS))(); } -std::future>> +UniqueFunction>()> CppFile::deferRebuild(StringRef NewContents, IntrusiveRefCntPtr VFS) { std::shared_ptr OldPreamble; @@ -1315,7 +1315,7 @@ CppFile::deferRebuild(StringRef NewContents, return Diagnostics; }; - return std::async(std::launch::deferred, FinishRebuild, NewContents.str()); + return BindWithForward(FinishRebuild, NewContents.str()); } std::shared_future> -- cgit v1.2.3