//===- 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 static std::vector Threads; bool lld::ThreadsEnabled = true; // Runs a given function in a new thread. void lld::runBackground(std::function 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(); }