[clang] [llvm] [LLVM] Add GNU make jobserver support (PR #145131)

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 07:21:49 PDT 2025


================
@@ -119,7 +130,24 @@ class ThreadPoolExecutor : public Executor {
       auto Task = std::move(WorkStack.back());
       WorkStack.pop_back();
       Lock.unlock();
-      Task();
+
+      if (TheJobserver) {
+        JobSlot Slot = TheJobserver->tryAcquire();
+        if (Slot.isValid()) {
+          Task();
+          TheJobserver->release(std::move(Slot));
+        } else {
+          // The task could not be run because no job slot was
+          // available. Re-queue the task so that another thread can try
+          // to run it later.
+          std::lock_guard<std::mutex> RequeueLock(Mutex);
+          WorkStack.push_back(std::move(Task));
+          Cond.notify_one();
+          // Yield to give another thread a chance to release a token.
+          std::this_thread::yield();
----------------
nga888 wrote:

This is yielding whilst holding onto the lock on `Mutex`.

https://github.com/llvm/llvm-project/pull/145131


More information about the llvm-commits mailing list