RBIT Instruction only available for ARMv6t2 and above.
[oota-llvm.git] / lib / Support / ThreadPool.cpp
index 40f1da9ef3f9c7e36625da345967332c1531f477..d4dcb2ee96df851e5542c80cef0d974b98325420 100644 (file)
@@ -31,7 +31,7 @@ ThreadPool::ThreadPool(unsigned ThreadCount)
   for (unsigned ThreadID = 0; ThreadID < ThreadCount; ++ThreadID) {
     Threads.emplace_back([&] {
       while (true) {
-        std::packaged_task<void()> Task;
+        PackagedTaskTy Task;
         {
           std::unique_lock<std::mutex> LockGuard(QueueLock);
           // Wait for tasks to be pushed in the queue
@@ -53,7 +53,11 @@ ThreadPool::ThreadPool(unsigned ThreadCount)
           Tasks.pop();
         }
         // Run the task we just grabbed
+#ifndef _MSC_VER
         Task();
+#else
+        Task(/* unused */ false);
+#endif
 
         {
           // Adjust `ActiveThreads`, in case someone waits on ThreadPool::wait()
@@ -75,10 +79,10 @@ void ThreadPool::wait() {
                            [&] { return Tasks.empty() && !ActiveThreads; });
 }
 
-std::shared_future<void> ThreadPool::asyncImpl(TaskTy Task) {
+std::shared_future<ThreadPool::VoidTy> ThreadPool::asyncImpl(TaskTy Task) {
   /// Wrap the Task in a packaged_task to return a future object.
-  std::packaged_task<void()> PackagedTask(std::move(Task));
-  std::future<void> Future = PackagedTask.get_future();
+  PackagedTaskTy PackagedTask(std::move(Task));
+  auto Future = PackagedTask.get_future();
   {
     // Lock the queue and push the new task
     std::unique_lock<std::mutex> LockGuard(QueueLock);
@@ -109,7 +113,7 @@ ThreadPool::ThreadPool() : ThreadPool(0) {}
 
 // No threads are launched, issue a warning if ThreadCount is not 0
 ThreadPool::ThreadPool(unsigned ThreadCount)
-    : ActiveThreads(0), EnableFlag(true) {
+    : ActiveThreads(0) {
   if (ThreadCount) {
     errs() << "Warning: request a ThreadPool with " << ThreadCount
            << " threads, but LLVM_ENABLE_THREADS has been turned off\n";
@@ -121,22 +125,30 @@ void ThreadPool::wait() {
   while (!Tasks.empty()) {
     auto Task = std::move(Tasks.front());
     Tasks.pop();
-    Task();
+#ifndef _MSC_VER
+        Task();
+#else
+        Task(/* unused */ false);
+#endif
   }
 }
 
-std::shared_future<void> ThreadPool::asyncImpl(TaskTy Task) {
+std::shared_future<ThreadPool::VoidTy> ThreadPool::asyncImpl(TaskTy Task) {
+#ifndef _MSC_VER
   // Get a Future with launch::deferred execution using std::async
   auto Future = std::async(std::launch::deferred, std::move(Task)).share();
   // Wrap the future so that both ThreadPool::wait() can operate and the
   // returned future can be sync'ed on.
-  std::packaged_task<void()> PackagedTask([Future]() { Future.get(); });
+  PackagedTaskTy PackagedTask([Future]() { Future.get(); });
+#else
+  auto Future = std::async(std::launch::deferred, std::move(Task), false).share();
+  PackagedTaskTy PackagedTask([Future](bool) -> bool { Future.get(); return false; });
+#endif
   Tasks.push(std::move(PackagedTask));
   return Future;
 }
 
 ThreadPool::~ThreadPool() {
-  EnableFlag = false;
   wait();
 }