[lld] r288631 - Run the last iteration of parallel_for_loop using a threadpool.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 4 18:07:30 PST 2016


Author: ruiu
Date: Sun Dec  4 20:07:29 2016
New Revision: 288631

URL: http://llvm.org/viewvc/llvm-project?rev=288631&view=rev
Log:
Run the last iteration of parallel_for_loop using a threadpool.

Remainders of tasks were ran in the main thread, so parallel_for_each
could theoretically take 2x time than the ideal.

Modified:
    lld/trunk/include/lld/Core/Parallel.h

Modified: lld/trunk/include/lld/Core/Parallel.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Parallel.h?rev=288631&r1=288630&r2=288631&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Parallel.h (original)
+++ lld/trunk/include/lld/Core/Parallel.h Sun Dec  4 20:07:29 2016
@@ -307,7 +307,7 @@ void parallel_for_each(IterTy Begin, Ite
     Tg.spawn([=, &Fn] { std::for_each(Begin, Begin + TaskSize, Fn); });
     Begin += TaskSize;
   }
-  std::for_each(Begin, End, Fn);
+  Tg.spawn([=, &Fn] { std::for_each(Begin, End, Fn); });
 }
 
 template <class IndexTy, class FuncTy>
@@ -325,8 +325,10 @@ void parallel_for(IndexTy Begin, IndexTy
     });
     Begin += TaskSize;
   }
-  for (; I < End; ++I)
-    Fn(I);
+  Tg.spawn([=, &Fn] {
+    for (IndexTy J = I; J < End; ++J)
+      Fn(J);
+  });
 }
 #endif
 } // end namespace lld




More information about the llvm-commits mailing list