LLVM: include/llvm/Support/Threading.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_SUPPORT_THREADING_H
15#define LLVM_SUPPORT_THREADING_H
16
19#include "llvm/Config/llvm-config.h"
21#include
22
23#if defined(_MSC_VER)
24
25
26#define LLVM_THREADING_USE_STD_CALL_ONCE 1
27#elif defined(LLVM_ON_UNIX) && \
28 (defined(_LIBCPP_VERSION) || \
29 !(defined(__NetBSD__) || defined(__OpenBSD__) || defined(__powerpc__)))
30
31
32
33#define LLVM_THREADING_USE_STD_CALL_ONCE 1
34#elif defined(LLVM_ON_UNIX) && \
35 (defined(__powerpc__) && defined(__LITTLE_ENDIAN__))
36#define LLVM_THREADING_USE_STD_CALL_ONCE 1
37#else
38#define LLVM_THREADING_USE_STD_CALL_ONCE 0
39#endif
40
41#if LLVM_THREADING_USE_STD_CALL_ONCE
42#include
43#else
45#endif
46
47namespace llvm {
48class Twine;
49
50
51
53
54#if LLVM_THREADING_USE_STD_CALL_ONCE
55
56 typedef std::once_flag once_flag;
57
58#else
59
61
62
63
64
65
66
69 };
70
71#endif
72
73
74
75
76
77
78
79
80
81
82
83
84
85 template <typename Function, typename... Args>
87#if LLVM_THREADING_USE_STD_CALL_ONCE
88 std::call_once(flag, std::forward(F),
89 std::forward(ArgList)...);
90#else
91
92
95 std::forward(F)(std::forward(ArgList)...);
101 } else {
102
105 while (tmp != Done) {
108 }
109 }
111#endif
112 }
113
114
116 public:
117
118
119
120
122
123
124
126
127
128
130
131
132
134
135
136
137
138
140
141
142
144 };
145
146
147
148
149
150
151 std::optional
153
154
155
156
157
158
159
160 inline ThreadPoolStrategy
165 return S;
166 }
167
168
169
170
171
173 std::optional S =
175 if (S)
176 return *S;
178 }
179
180
181
182
183
187 return S;
188 }
189
190
191
192
193
195 std::optional S =
197 if (S)
198 return *S;
200 }
201
202
203
204
209 return S;
210 }
211
212
213
214
215
217
218
219
221
222
223
224
225
226
227
229
230
231
232
233
234
235
237
238
239
240
242
243
245
246
247
248
250
252
253
254
256
257
258
259
260
262
263
265 };
268}
269
270#endif
This file implements the BitVector class.
#define TsanHappensBefore(cv)
#define TsanHappensAfter(cv)
#define TsanIgnoreWritesEnd()
#define TsanIgnoreWritesBegin()
static cl::opt< int > ThreadCount("threads", cl::init(0))
StringRef - Represent a constant reference to a string, i.e.
This tells how a thread pool will be used.
std::optional< unsigned > compute_cpu_socket(unsigned ThreadPoolNum) const
Finds the CPU socket where a thread should go.
unsigned ThreadsRequested
void apply_thread_strategy(unsigned ThreadPoolNum) const
Assign the current thread to an ideal hardware CPU or NUMA node.
unsigned compute_thread_count() const
Retrieves the max available threads for the current strategy.
cas_flag CompareAndSwap(volatile cas_flag *ptr, cas_flag new_value, cas_flag old_value)
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)
Returns a thread strategy for tasks requiring significant memory or other resources.
@ Low
Lower the current thread's priority such that it does not affect foreground tasks significantly.
@ Background
Lower the current thread's priority as much as possible.
SetThreadPriorityResult set_thread_priority(ThreadPriority Priority)
constexpr bool llvm_is_multithreaded()
Returns true if LLVM is compiled with support for multi-threading, and false otherwise.
llvm::BitVector get_thread_affinity_mask()
Returns a mask that represents on which hardware thread, core, CPU, NUMA group, the calling thread ca...
uint32_t get_max_thread_name_length()
Get the maximum length of a thread name on this platform.
unsigned get_cpus()
Returns how many physical CPUs or NUMA groups the system has.
ThreadPoolStrategy optimal_concurrency(unsigned TaskCount=0)
Returns an optimal thread strategy to execute specified amount of tasks.
void set_thread_name(const Twine &Name)
Set the name of the current thread.
void get_thread_name(SmallVectorImpl< char > &Name)
Get the name of the current thread.
int get_physical_cores()
Returns how many physical cores (as opposed to logical cores returned from thread::hardware_concurren...
std::optional< ThreadPoolStrategy > get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default={})
Build a strategy from a number of threads as a string provided in Num.
uint64_t get_threadid()
Return the current thread id, as used in various OS system calls.
void call_once(once_flag &flag, Function &&F, Args &&... ArgList)
Execute the function specified as a parameter once.
@ Default
The result values are uniform if and only if all operands are uniform.
The llvm::once_flag structure.
volatile sys::cas_flag status