[clang] [llvm] [LLVM] Add GNU make jobserver support (PR #145131)
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 1 19:30:27 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();
----------------
yxsamliu wrote:
actually after we change the code to re-use job slots and use exponential backoff, this issue no longer happens
https://github.com/llvm/llvm-project/pull/145131
More information about the cfe-commits
mailing list