5#ifndef RUNTIME_VM_THREAD_POOL_H_
6#define RUNTIME_VM_THREAD_POOL_H_
31 virtual void Run() = 0;
34 DISALLOW_COPY_AND_ASSIGN(
Task);
37 explicit ThreadPool(uintptr_t max_pool_size = 0);
44 template <
typename T,
typename... Args>
46 return RunImpl(std::unique_ptr<Task>(
new T(std::forward<Args>(
args)...)));
89 bool is_blocked_ =
false;
111 bool RunImpl(std::unique_ptr<Task> task);
112 void WorkerLoop(Worker* worker);
114 Worker* ScheduleTaskLocked(
MonitorLocker* ml, std::unique_ptr<Task> task);
116 void IdleToRunningLocked(Worker* worker);
117 void RunningToIdleLocked(Worker* worker);
118 void IdleToDeadLocked(Worker* worker);
119 void ObtainDeadWorkersLocked(WorkerList* dead_workers_to_join);
120 void JoinDeadWorkersLocked(WorkerList* dead_workers_to_join);
123 bool shutting_down_ =
false;
124 uint64_t count_running_ = 0;
125 uint64_t count_idle_ = 0;
126 uint64_t count_dead_ = 0;
127 WorkerList running_workers_;
128 WorkerList idle_workers_;
129 WorkerList dead_workers_;
130 uint64_t pending_tasks_ = 0;
134 std::atomic<bool> all_workers_dead_;
136 uintptr_t max_pool_size_ = 0;
uint64_t workers_started() const
bool ShuttingDownLocked()
uint64_t workers_stopped() const
bool Run(Args &&... args)
ThreadPool(uintptr_t max_pool_size=0)
void MarkCurrentWorkerAsBlocked()
virtual void OnEnterIdleLocked(MonitorLocker *ml)
bool CurrentThreadIsWorker()
void MarkCurrentWorkerAsUnBlocked()
bool TasksWaitingToRunLocked()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static int Main(int argc, const char **argv)