1 //===-- llvm/Support/Threading.h - Control multithreading mode --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares helper functions for running LLVM in a multi-threaded
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_SUPPORT_THREADING_H
16 #define LLVM_SUPPORT_THREADING_H
18 #if !defined(__MINGW__)
23 /// Returns true if LLVM is compiled with support for multi-threading, and
25 bool llvm_is_multithreaded();
27 /// llvm_execute_on_thread - Execute the given \p UserFn on a separate
28 /// thread, passing it the provided \p UserData.
30 /// This function does not guarantee that the code will actually be executed
31 /// on a separate thread or honoring the requested stack size, but tries to do
32 /// so where system support is available.
34 /// \param UserFn - The callback to execute.
35 /// \param UserData - An argument to pass to the callback function.
36 /// \param RequestedStackSize - If non-zero, a requested size (in bytes) for
38 void llvm_execute_on_thread(void (*UserFn)(void*), void *UserData,
39 unsigned RequestedStackSize = 0);
41 template <void (*UserFn)(void)> void llvm_call_once() {
43 #if !defined(__MINGW__)
44 static std::once_flag flag;
45 std::call_once(flag, UserFn);
48 struct InitOnceWrapper {
49 InitOnceWrapper() { UserFn(); }
51 static InitOnceWrapper InitOnceVar;