summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2017-10-10 16:12:54 +0000
committerIlya Biryukov <ibiryukov@google.com>2017-10-10 16:12:54 +0000
commit98a1fd7f96cdabfff1c0b9b5448423f3cf2ac1d5 (patch)
tree4b1c53a2f397aef1c5f323b5d50cefad9d869a04
parenteab499d31b27ebe028896ac90b4ef56e6f7e5acd (diff)
downloadbcm5719-llvm-98a1fd7f96cdabfff1c0b9b5448423f3cf2ac1d5.tar.gz
bcm5719-llvm-98a1fd7f96cdabfff1c0b9b5448423f3cf2ac1d5.zip
[clangd] Use UniqueFunction for deferred computations.
Previsouly, `std::future` that were results of `std::async(std::launch::deferred, ...` were used. llvm-svn: 315325
-rw-r--r--clang-tools-extra/clangd/ClangdServer.cpp15
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.cpp14
-rw-r--r--clang-tools-extra/clangd/ClangdUnit.h18
3 files changed, 24 insertions, 23 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index f24b4c5fe45..0af9e6fe003 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -413,8 +413,9 @@ std::future<void> ClangdServer::scheduleReparseAndDiags(
Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> TaggedFS) {
assert(Contents.Draft && "Draft must have contents");
- std::future<llvm::Optional<std::vector<DiagWithFixIts>>> DeferredRebuild =
- Resources->deferRebuild(*Contents.Draft, TaggedFS.Value);
+ UniqueFunction<llvm::Optional<std::vector<DiagWithFixIts>>()>
+ DeferredRebuild =
+ Resources->deferRebuild(*Contents.Draft, TaggedFS.Value);
std::promise<void> DonePromise;
std::future<void> DoneFuture = DonePromise.get_future();
@@ -423,7 +424,7 @@ std::future<void> ClangdServer::scheduleReparseAndDiags(
VFSTag Tag = TaggedFS.Tag;
auto ReparseAndPublishDiags =
[this, FileStr, Version,
- Tag](std::future<llvm::Optional<std::vector<DiagWithFixIts>>>
+ Tag](UniqueFunction<llvm::Optional<std::vector<DiagWithFixIts>>()>
DeferredRebuild,
std::promise<void> DonePromise) -> void {
FulfillPromiseGuard Guard(DonePromise);
@@ -432,7 +433,7 @@ std::future<void> ClangdServer::scheduleReparseAndDiags(
if (CurrentVersion != Version)
return; // This request is outdated
- auto Diags = DeferredRebuild.get();
+ auto Diags = DeferredRebuild();
if (!Diags)
return; // A new reparse was requested before this one completed.
@@ -467,11 +468,11 @@ ClangdServer::scheduleCancelRebuild(std::shared_ptr<CppFile> Resources) {
return DoneFuture;
}
- std::future<void> DeferredCancel = Resources->deferCancelRebuild();
+ UniqueFunction<void()> DeferredCancel = Resources->deferCancelRebuild();
auto CancelReparses = [Resources](std::promise<void> DonePromise,
- std::future<void> DeferredCancel) {
+ UniqueFunction<void()> DeferredCancel) {
FulfillPromiseGuard Guard(DonePromise);
- DeferredCancel.get();
+ DeferredCancel();
};
WorkScheduler.addToFront(std::move(CancelReparses), std::move(DonePromise),
std::move(DeferredCancel));
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<void> CppFile::deferCancelRebuild() {
+UniqueFunction<void()> CppFile::deferCancelRebuild() {
std::unique_lock<std::mutex> Lock(Mutex);
// Cancel an ongoing rebuild, if any, and wait for it to finish.
unsigned RequestRebuildCounter = ++this->RebuildCounter;
@@ -1143,7 +1143,7 @@ std::future<void> CppFile::deferCancelRebuild() {
RebuildCond.notify_all();
std::shared_ptr<CppFile> That = shared_from_this();
- return std::async(std::launch::deferred, [That, RequestRebuildCounter]() {
+ return [That, RequestRebuildCounter]() {
std::unique_lock<std::mutex> Lock(That->Mutex);
CppFile *This = &*That;
This->RebuildCond.wait(Lock, [This, RequestRebuildCounter]() {
@@ -1158,16 +1158,16 @@ std::future<void> CppFile::deferCancelRebuild() {
// Set empty results for Promises.
That->PreamblePromise.set_value(nullptr);
That->ASTPromise.set_value(std::make_shared<ParsedASTWrapper>(llvm::None));
- });
+ };
}
llvm::Optional<std::vector<DiagWithFixIts>>
CppFile::rebuild(StringRef NewContents,
IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
- return deferRebuild(NewContents, std::move(VFS)).get();
+ return deferRebuild(NewContents, std::move(VFS))();
}
-std::future<llvm::Optional<std::vector<DiagWithFixIts>>>
+UniqueFunction<llvm::Optional<std::vector<DiagWithFixIts>>()>
CppFile::deferRebuild(StringRef NewContents,
IntrusiveRefCntPtr<vfs::FileSystem> VFS) {
std::shared_ptr<const PreambleData> 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<std::shared_ptr<const PreambleData>>
diff --git a/clang-tools-extra/clangd/ClangdUnit.h b/clang-tools-extra/clangd/ClangdUnit.h
index 36bf8c86e05..ad200c285ae 100644
--- a/clang-tools-extra/clangd/ClangdUnit.h
+++ b/clang-tools-extra/clangd/ClangdUnit.h
@@ -10,6 +10,7 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
+#include "Function.h"
#include "Path.h"
#include "Protocol.h"
#include "clang/Frontend/FrontendAction.h"
@@ -157,12 +158,11 @@ public:
void cancelRebuild();
/// Similar to deferRebuild, but sets both Preamble and AST to nulls instead
- /// of doing an actual parsing. Returned future is a deferred computation that
- /// will wait for any ongoing rebuilds to finish and actually set the AST and
- /// Preamble to nulls. It can be run on a different thread.
- /// This function is useful to cancel ongoing rebuilds, if any, before
- /// removing CppFile.
- std::future<void> deferCancelRebuild();
+ /// of doing an actual parsing. Returned function is a deferred computation
+ /// that will wait for any ongoing rebuilds to finish and actually set the AST
+ /// and Preamble to nulls. It can be run on a different thread. This function
+ /// is useful to cancel ongoing rebuilds, if any, before removing CppFile.
+ UniqueFunction<void()> deferCancelRebuild();
/// Rebuild AST and Preamble synchronously on the calling thread.
/// Returns a list of diagnostics or a llvm::None, if another rebuild was
@@ -175,8 +175,8 @@ public:
/// rebuild, that can be called on a different thread.
/// After calling this method, resources, available via futures returned by
/// getPreamble() and getAST(), will be waiting for rebuild to finish. A
- /// future fininshing rebuild, returned by this function, must be
- /// computed(i.e. get() should be called on it) in order to make those
+ /// continuation fininshing rebuild, returned by this function, must be
+ /// computed(i.e., operator() must be called on it) in order to make those
/// resources ready. If deferRebuild is called again before the rebuild is
/// finished (either because returned future had not been called or because it
/// had not returned yet), the previous rebuild request is cancelled and the
@@ -185,7 +185,7 @@ public:
/// The future to finish rebuild returns a list of diagnostics built during
/// reparse, or None, if another deferRebuild was called before this
/// rebuild was finished.
- std::future<llvm::Optional<std::vector<DiagWithFixIts>>>
+ UniqueFunction<llvm::Optional<std::vector<DiagWithFixIts>>()>
deferRebuild(StringRef NewContents, IntrusiveRefCntPtr<vfs::FileSystem> VFS);
/// Returns a future to get the most fresh PreambleData for a file. The
OpenPOWER on IntegriCloud