#include <thread_pool.h>
Definition at line 20 of file thread_pool.h.
◆ ThreadPool()
dart::ThreadPool::ThreadPool |
( |
uintptr_t |
max_pool_size = 0 | ) |
|
|
explicit |
Definition at line 37 of file thread_pool.cc.
38 : all_workers_dead_(false), max_pool_size_(max_pool_size) {}
◆ ~ThreadPool()
dart::ThreadPool::~ThreadPool |
( |
| ) |
|
|
virtual |
◆ CurrentThreadIsWorker()
bool dart::ThreadPool::CurrentThreadIsWorker |
( |
| ) |
|
Definition at line 99 of file thread_pool.cc.
99 {
100 auto worker =
102 return worker != nullptr && worker->pool_ == this;
103}
static OSThread * Current()
◆ MarkCurrentWorkerAsBlocked()
void dart::ThreadPool::MarkCurrentWorkerAsBlocked |
( |
| ) |
|
Definition at line 105 of file thread_pool.cc.
105 {
106 auto worker =
108 Worker* new_worker = nullptr;
109 if (worker != nullptr) {
110 MonitorLocker ml(&pool_monitor_);
111 ASSERT(!worker->is_blocked_);
112 worker->is_blocked_ = true;
113 if (max_pool_size_ > 0) {
114 ++max_pool_size_;
115
116
117
118
119 if (idle_workers_.
IsEmpty() && pending_tasks_ > 0) {
120 new_worker = new Worker(this);
121 idle_workers_.
Append(new_worker);
122 count_idle_++;
123 }
124 }
125 }
126 if (new_worker != nullptr) {
127 new_worker->StartThread();
128 }
129}
◆ MarkCurrentWorkerAsUnBlocked()
void dart::ThreadPool::MarkCurrentWorkerAsUnBlocked |
( |
| ) |
|
Definition at line 131 of file thread_pool.cc.
131 {
132 auto worker =
134 if (worker != nullptr) {
135 MonitorLocker ml(&pool_monitor_);
136 if (worker->is_blocked_) {
137 worker->is_blocked_ = false;
138 if (max_pool_size_ > 0) {
139 --max_pool_size_;
140 ASSERT(max_pool_size_ > 0);
141 }
142 }
143 }
144}
◆ OnEnterIdleLocked()
virtual void dart::ThreadPool::OnEnterIdleLocked |
( |
MonitorLocker * |
ml | ) |
|
|
inlineprotectedvirtual |
◆ Run()
template<typename
T , typename... Args>
bool dart::ThreadPool::Run |
( |
Args &&... |
args | ) |
|
|
inline |
Definition at line 45 of file thread_pool.h.
45 {
46 return RunImpl(std::unique_ptr<Task>(
new T(std::forward<Args>(
args)...)));
47 }
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
◆ Shutdown()
void dart::ThreadPool::Shutdown |
( |
| ) |
|
Definition at line 44 of file thread_pool.cc.
44 {
45 {
46 MonitorLocker ml(&pool_monitor_);
47
48
49 shutting_down_ = true;
50
52
53 all_workers_dead_ = true;
54 } else {
55
56 ml.NotifyAll();
57 }
58 }
59
60
61
62 {
63 MonitorLocker eml(&exit_monitor_);
64 while (!all_workers_dead_) {
65 eml.Wait();
66 }
67 }
69 ASSERT(count_running_ == 0);
72
73 WorkerList dead_workers_to_join;
74 {
75 MonitorLocker ml(&pool_monitor_);
76 ObtainDeadWorkersLocked(&dead_workers_to_join);
77 }
78 JoinDeadWorkersLocked(&dead_workers_to_join);
79
82}
◆ ShuttingDownLocked()
bool dart::ThreadPool::ShuttingDownLocked |
( |
| ) |
|
|
inlineprotected |
◆ TasksWaitingToRunLocked()
bool dart::ThreadPool::TasksWaitingToRunLocked |
( |
| ) |
|
|
inlineprotected |
◆ workers_started()
uint64_t dart::ThreadPool::workers_started |
( |
| ) |
const |
|
inline |
Definition at line 65 of file thread_pool.h.
65{ return count_idle_ + count_running_; }
◆ workers_stopped()
uint64_t dart::ThreadPool::workers_stopped |
( |
| ) |
const |
|
inline |
The documentation for this class was generated from the following files: