Support: Support LLVM_ENABLE_THREADS=0 in llvm/Support/thread.h.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 31 Aug 2015 00:09:01 +0000 (00:09 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 31 Aug 2015 00:09:01 +0000 (00:09 +0000)
Specifically, the header now provides llvm::thread, which is either a
typedef of std::thread or a replacement that calls the function synchronously
depending on the value of LLVM_ENABLE_THREADS.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246402 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/thread.h
lib/CodeGen/ParallelCG.cpp

index b61177d59891bb8a33f9ffd1b4ba59a2f89862ab..2d1f1b3a3ec0efa2c7103be970a9ed6f6af66315 100644 (file)
@@ -8,13 +8,19 @@
 //===----------------------------------------------------------------------===//
 //
 // This header is a wrapper for <thread> that works around problems with the
-// MSVC headers when exceptions are disabled.
+// MSVC headers when exceptions are disabled. It also provides llvm::thread,
+// which is either a typedef of std::thread or a replacement that calls the
+// function synchronously depending on the value of LLVM_ENABLE_THREADS.
 //
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_SUPPORT_THREAD_H
 #define LLVM_SUPPORT_THREAD_H
 
+#include "llvm/Config/llvm-config.h"
+
+#if LLVM_ENABLE_THREADS
+
 #ifdef _MSC_VER
 // concrt.h depends on eh.h for __uncaught_exception declaration
 // even if we disable exceptions.
 #pragma warning(pop)
 #endif
 
+namespace llvm {
+typedef std::thread thread;
+}
+
+#else // !LLVM_ENABLE_THREADS
+
+namespace llvm {
+
+struct thread {
+  thread() {}
+  thread(thread &&other) {}
+  template <class Function, class... Args>
+  explicit thread(Function &&f, Args &&... args) {
+    f(std::forward<Args>(args)...);
+  }
+  thread(const thread &) = delete;
+
+  void join() {}
+};
+
+}
+
+#endif // LLVM_ENABLE_THREADS
+
 #endif
index 3e6a71d602b5cb89e3977d9b75c12c90ff372e97..748d3883ea1fe0bf5a85defd690444bb2c41e5b1 100644 (file)
@@ -56,7 +56,7 @@ llvm::splitCodeGen(std::unique_ptr<Module> M,
     return M;
   }
 
-  std::vector<std::thread> Threads;
+  std::vector<thread> Threads;
   SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr<Module> MPart) {
     // We want to clone the module in a new context to multi-thread the codegen.
     // We do it by serializing partition modules to bitcode (while still on the
@@ -88,7 +88,7 @@ llvm::splitCodeGen(std::unique_ptr<Module> M,
         std::move(BC));
   });
 
-  for (std::thread &T : Threads)
+  for (thread &T : Threads)
     T.join();
 
   return {};