[PATCH] D69328: [clangd] Propogate context in TUScheduler::run

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 23 02:36:28 PDT 2019


kadircet updated this revision to Diff 226104.
kadircet added a comment.

- Add tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69328/new/

https://reviews.llvm.org/D69328

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp


Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -688,6 +688,24 @@
   S.run("add 2", [&] { Counter += 2; });
   ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
   EXPECT_EQ(Counter.load(), 3);
+
+  Notification OutsideCtxDestroyed;
+  Notification ScopeExit;
+  Counter.store(0);
+  {
+    WithContextValue Context(llvm::make_scope_exit([&] {
+      ++Counter;
+      ScopeExit.notify();
+    }));
+    S.run("props context", [&] {
+      OutsideCtxDestroyed.wait();
+      // scope exit shouldn't be called until run finishes.
+      EXPECT_THAT(Counter.load(), 0);
+    });
+  }
+  OutsideCtxDestroyed.notify();
+  ScopeExit.wait();
+  EXPECT_THAT(Counter.load(), 1);
 }
 
 TEST_F(TUSchedulerTests, TUStatus) {
Index: clang-tools-extra/clangd/TUScheduler.cpp
===================================================================
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -919,7 +919,9 @@
                       llvm::unique_function<void()> Action) {
   if (!PreambleTasks)
     return Action();
-  PreambleTasks->runAsync(Name, std::move(Action));
+  auto ActionWithCtx = [Ctx = Context::current().clone(),
+                        Action = std::move(Action)]() mutable { Action(); };
+  PreambleTasks->runAsync(Name, std::move(ActionWithCtx));
 }
 
 void TUScheduler::runWithAST(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69328.226104.patch
Type: text/x-patch
Size: 1541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191023/e2abe098/attachment.bin>


More information about the cfe-commits mailing list