diff options
author | Bob Haarman <llvm@inglorion.net> | 2017-10-13 18:22:55 +0000 |
---|---|---|
committer | Bob Haarman <llvm@inglorion.net> | 2017-10-13 18:22:55 +0000 |
commit | 4f5c8c29ac38fc459d045cb9968a10764eba0a1e (patch) | |
tree | f14f3f07f7515f68593805c08e388656661e804f /lld/Common/Threads.cpp | |
parent | bfc20343a3f215e737dad244e77bbeb1ce02583c (diff) | |
download | bcm5719-llvm-4f5c8c29ac38fc459d045cb9968a10764eba0a1e.tar.gz bcm5719-llvm-4f5c8c29ac38fc459d045cb9968a10764eba0a1e.zip |
[lld] Move Threads to Common
Summary:
This will allow using the functionality from other linkers. It is also
a prerequisite for sharing the error logging code.
Reviewers: ruiu
Reviewed By: ruiu
Subscribers: emaste, mgorny, llvm-commits
Differential Revision: https://reviews.llvm.org/D38822
llvm-svn: 315725
Diffstat (limited to 'lld/Common/Threads.cpp')
-rw-r--r-- | lld/Common/Threads.cpp | 31 |
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(); +} |