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
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()
[&] { 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);
// 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";
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();
}