Threading.h: Use \tparam for template parameters. [-Wdocumentation]
[oota-llvm.git] / include / llvm / Support / Threading.h
1 //===-- llvm/Support/Threading.h - Control multithreading mode --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares helper functions for running LLVM in a multi-threaded
11 // environment.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_THREADING_H
16 #define LLVM_SUPPORT_THREADING_H
17
18 #if !defined(__MINGW__)
19 #include <mutex>
20 #endif
21
22 namespace llvm {
23   /// Returns true if LLVM is compiled with support for multi-threading, and
24   /// false otherwise.
25   bool llvm_is_multithreaded();
26
27   /// llvm_execute_on_thread - Execute the given \p UserFn on a separate
28   /// thread, passing it the provided \p UserData.
29   ///
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.
33   ///
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
37   /// the thread stack.
38   void llvm_execute_on_thread(void (*UserFn)(void*), void *UserData,
39                               unsigned RequestedStackSize = 0);
40
41 /// \brief Execute the function specified as a template parameter once.
42 ///
43 /// Calls \p UserFn once ever. The call uniqueness is based on the address of
44 /// the function passed in via the template arguement. This means no matter how
45 /// many times you call llvm_call_once<foo>() in the same or different
46 /// locations, foo will only be called once.
47 ///
48 /// Typical usage:
49 /// \code
50 ///   void foo() {...};
51 ///   ...
52 ///   llvm_call_once<foo>();
53 /// \endcode
54 ///
55 /// \tparam UserFn Function to call once.
56 template <void (*UserFn)(void)> void llvm_call_once() {
57 #if !defined(__MINGW__)
58   static std::once_flag flag;
59   std::call_once(flag, UserFn);
60 #else
61   struct InitOnceWrapper {
62     InitOnceWrapper() { UserFn(); }
63   };
64   static InitOnceWrapper InitOnceVar;
65 #endif
66 }
67 }
68
69 #endif