11 #include "llvm/Config/llvm-config.h" 13 #if LLVM_ENABLE_THREADS 28 virtual ~Executor() =
default;
31 static Executor *getDefaultExecutor();
36 class ConcRTExecutor :
public Executor {
40 std::function<void()> Task;
42 static void run(
void *
P) {
43 Taskish *Self =
static_cast<Taskish *
>(
P);
45 concurrency::Free(Self);
51 Concurrency::CurrentScheduler::ScheduleTask(
52 Taskish::run,
new (concurrency::Alloc(
sizeof(Taskish))) Taskish(
F));
56 Executor *Executor::getDefaultExecutor() {
57 static ConcRTExecutor exec;
64 class ThreadPoolExecutor :
public Executor {
71 for (
size_t i = 1; i < ThreadCount; ++i) {
78 ~ThreadPoolExecutor()
override {
97 Cond.wait(
Lock, [&] {
return Stop || !WorkStack.empty(); });
100 auto Task = WorkStack.top();
108 std::atomic<bool> Stop{
false};
109 std::stack<std::function<void()>> WorkStack;
111 std::condition_variable Cond;
115 Executor *Executor::getDefaultExecutor() {
116 static ThreadPoolExecutor exec;
124 Executor::getDefaultExecutor()->add([&,
F] {
129 #endif // LLVM_ENABLE_THREADS This class represents lattice values for constants.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
void spawn(std::function< void()> f)
print Print MemDeps of function
unsigned hardware_concurrency()
Get the number of threads that the current program can execute concurrently.