summaryrefslogtreecommitdiffstats
path: root/lld/Common/Threads.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/Common/Threads.cpp')
-rw-r--r--lld/Common/Threads.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lld/Common/Threads.cpp b/lld/Common/Threads.cpp
new file mode 100644
index 00000000000..86c8f43f5fc
--- /dev/null
+++ b/lld/Common/Threads.cpp
@@ -0,0 +1,31 @@
+//===- Threads.cpp --------------------------------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Common/Threads.h"
+#include <thread>
+
+static std::vector<std::thread> Threads;
+
+bool lld::ThreadsEnabled = true;
+
+// Runs a given function in a new thread.
+void lld::runBackground(std::function<void()> Fn) {
+ Threads.emplace_back(Fn);
+}
+
+// Wait for all threads spawned for runBackground() to finish.
+//
+// You need to call this function from the main thread before exiting
+// because it is not defined what will happen to non-main threads when
+// the main thread exits.
+void lld::waitForBackgroundThreads() {
+ for (std::thread &T : Threads)
+ if (T.joinable())
+ T.join();
+}
OpenPOWER on IntegriCloud