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

Reply via email to