[PATCH] D90747: [clangd] Mark AsyncTaskRunner::runAsync as const

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 02:14:20 PST 2020


kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, arphaman.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

RunAsync performs a write that's internally synchronized, so in theory
it shouldn't introduce any data-races. This will enable spawning async tasks in
const contexts.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90747

Files:
  clang-tools-extra/clangd/support/Threading.cpp
  clang-tools-extra/clangd/support/Threading.h


Index: clang-tools-extra/clangd/support/Threading.h
===================================================================
--- clang-tools-extra/clangd/support/Threading.h
+++ clang-tools-extra/clangd/support/Threading.h
@@ -110,12 +110,13 @@
   void wait() const { (void)wait(Deadline::infinity()); }
   LLVM_NODISCARD bool wait(Deadline D) const;
   // The name is used for tracing and debugging (e.g. to name a spawned thread).
-  void runAsync(const llvm::Twine &Name, llvm::unique_function<void()> Action);
+  void runAsync(const llvm::Twine &Name,
+                llvm::unique_function<void()> Action) const;
 
 private:
   mutable std::mutex Mutex;
   mutable std::condition_variable TasksReachedZero;
-  std::size_t InFlightTasks = 0;
+  mutable std::size_t InFlightTasks = 0;
 };
 
 /// Runs \p Action asynchronously with a new std::thread. The context will be
Index: clang-tools-extra/clangd/support/Threading.cpp
===================================================================
--- clang-tools-extra/clangd/support/Threading.cpp
+++ clang-tools-extra/clangd/support/Threading.cpp
@@ -70,7 +70,7 @@
 }
 
 void AsyncTaskRunner::runAsync(const llvm::Twine &Name,
-                               llvm::unique_function<void()> Action) {
+                               llvm::unique_function<void()> Action) const {
   {
     std::lock_guard<std::mutex> Lock(Mutex);
     ++InFlightTasks;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90747.302787.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201104/cbd17ad0/attachment.bin>


More information about the cfe-commits mailing list