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 // TThis file defines llvm_start_multithreaded() and friends.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_THREADING_H
15 #define LLVM_SUPPORT_THREADING_H
18 /// llvm_start_multithreaded - Allocate and initialize structures needed to
19 /// make LLVM safe for multithreading. The return value indicates whether
20 /// multithreaded initialization succeeded. LLVM will still be operational
21 /// on "failed" return, and will still be safe for hosting threading
22 /// applications in the JIT, but will not be safe for concurrent calls to the
24 /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
25 bool llvm_start_multithreaded();
27 /// llvm_stop_multithreaded - Deallocate structures necessary to make LLVM
28 /// safe for multithreading.
29 /// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
30 void llvm_stop_multithreaded();
32 /// llvm_is_multithreaded - Check whether LLVM is executing in thread-safe
34 bool llvm_is_multithreaded();
36 /// acquire_global_lock - Acquire the global lock. This is a no-op if called
37 /// before llvm_start_multithreaded().
38 void llvm_acquire_global_lock();
40 /// release_global_lock - Release the global lock. This is a no-op if called
41 /// before llvm_start_multithreaded().
42 void llvm_release_global_lock();
44 /// llvm_execute_on_thread - Execute the given \p UserFn on a separate
45 /// thread, passing it the provided \p UserData.
47 /// This function does not guarantee that the code will actually be executed
48 /// on a separate thread or honoring the requested stack size, but tries to do
49 /// so where system support is available.
51 /// \param UserFn - The callback to execute.
52 /// \param UserData - An argument to pass to the callback function.
53 /// \param RequestedStackSize - If non-zero, a requested size (in bytes) for
55 void llvm_execute_on_thread(void (*UserFn)(void*), void *UserData,
56 unsigned RequestedStackSize = 0);