[clang] [llvm] [LLVM] Add GNU make jobserver support (PR #145131)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 4 21:56:37 PDT 2025
================
@@ -133,6 +140,85 @@ void StdThreadPool::processTasks(ThreadPoolTaskGroup *WaitingForGroup) {
}
}
+/// Main loop for worker threads when using a jobserver.
+/// This function uses a two-level queue; it first acquires a job slot from the
+/// external jobserver, then retrieves a task from the internal queue.
+/// This allows the thread pool to cooperate with build systems like `make -j`.
+void StdThreadPool::processTasksWithJobserver() {
+ while (true) {
+ // Acquire a job slot from the external jobserver.
+ // This polls for a slot and yields the thread to avoid a high-CPU wait.
+ JobSlot Slot;
+ while (true) {
+ // Return if the thread pool is shutting down.
+ {
+ std::unique_lock<std::mutex> LockGuard(QueueLock);
+ if (!EnableFlag)
+ return;
+ }
+ Slot = TheJobserver->tryAcquire();
+ if (Slot.isValid())
+ break; // Successfully acquired a slot.
+
+ // If the jobserver is busy, yield to let other threads run.
+ std::this_thread::yield();
----------------
yxsamliu wrote:
will use ExponentialBackoff for now
https://github.com/llvm/llvm-project/pull/145131
More information about the llvm-commits
mailing list