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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits