4768d86de991c002891e270c2f44f32dee4a5728
[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 // TThis file defines llvm_start_multithreaded() and friends.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SUPPORT_THREADING_H
15 #define LLVM_SUPPORT_THREADING_H
16
17 #include "llvm/Support/Mutex.h"
18
19 namespace llvm {
20   /// llvm_get_global_lock - returns the llvm global lock object.
21   sys::Mutex& llvm_get_global_lock();
22
23   /// llvm_start_multithreaded - Allocate and initialize structures needed to
24   /// make LLVM safe for multithreading.  The return value indicates whether
25   /// multithreaded initialization succeeded.  LLVM will still be operational
26   /// on "failed" return, and will still be safe for hosting threading
27   /// applications in the JIT, but will not be safe for concurrent calls to the
28   /// LLVM APIs.
29   /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
30   bool llvm_start_multithreaded();
31
32   /// llvm_stop_multithreaded - Deallocate structures necessary to make LLVM
33   /// safe for multithreading.
34   /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
35   void llvm_stop_multithreaded();
36
37   /// llvm_is_multithreaded - Check whether LLVM is executing in thread-safe
38   /// mode or not.
39   bool llvm_is_multithreaded();
40
41   /// llvm_execute_on_thread - Execute the given \p UserFn on a separate
42   /// thread, passing it the provided \p UserData.
43   ///
44   /// This function does not guarantee that the code will actually be executed
45   /// on a separate thread or honoring the requested stack size, but tries to do
46   /// so where system support is available.
47   ///
48   /// \param UserFn - The callback to execute.
49   /// \param UserData - An argument to pass to the callback function.
50   /// \param RequestedStackSize - If non-zero, a requested size (in bytes) for
51   /// the thread stack.
52   void llvm_execute_on_thread(void (*UserFn)(void*), void *UserData,
53                               unsigned RequestedStackSize = 0);
54 }
55
56 #endif