@@ -47,7 +47,7 @@ static void BackgroundRunner(void* data) {
47
47
class BackgroundTaskRunner ::DelayedTaskScheduler {
48
48
public:
49
49
explicit DelayedTaskScheduler (TaskQueue<Task>* tasks)
50
- : pending_worker_tasks_ (tasks) {}
50
+ : background_tasks_ (tasks) {}
51
51
52
52
std::unique_ptr<uv_thread_t > Start () {
53
53
auto start_thread = [](void * data) {
@@ -139,7 +139,7 @@ class BackgroundTaskRunner::DelayedTaskScheduler {
139
139
static void RunTask (uv_timer_t * timer) {
140
140
DelayedTaskScheduler* scheduler =
141
141
ContainerOf (&DelayedTaskScheduler::loop_, timer->loop );
142
- scheduler->pending_worker_tasks_ ->Push (scheduler->TakeTimerTask (timer));
142
+ scheduler->background_tasks_ ->Push (scheduler->TakeTimerTask (timer));
143
143
}
144
144
145
145
std::unique_ptr<Task> TakeTimerTask (uv_timer_t * timer) {
@@ -153,7 +153,7 @@ class BackgroundTaskRunner::DelayedTaskScheduler {
153
153
}
154
154
155
155
uv_sem_t ready_;
156
- TaskQueue<v8::Task>* pending_worker_tasks_ ;
156
+ TaskQueue<v8::Task>* background_tasks_ ;
157
157
158
158
TaskQueue<v8::Task> tasks_;
159
159
uv_loop_t loop_;
@@ -162,17 +162,20 @@ class BackgroundTaskRunner::DelayedTaskScheduler {
162
162
};
163
163
164
164
BackgroundTaskRunner::BackgroundTaskRunner (int thread_pool_size) {
165
- Mutex::ScopedLock lock (platform_workers_mutex_);
166
- pending_platform_workers_ = thread_pool_size;
165
+ Mutex platform_workers_mutex;
166
+ ConditionVariable platform_workers_ready;
167
+
168
+ Mutex::ScopedLock lock (platform_workers_mutex);
169
+ int pending_platform_workers = thread_pool_size;
167
170
168
171
delayed_task_scheduler_.reset (
169
172
new DelayedTaskScheduler (&background_tasks_));
170
173
threads_.push_back (delayed_task_scheduler_->Start ());
171
174
172
175
for (int i = 0 ; i < thread_pool_size; i++) {
173
176
PlatformWorkerData* worker_data = new PlatformWorkerData{
174
- &background_tasks_, &platform_workers_mutex_ ,
175
- &platform_workers_ready_ , &pending_platform_workers_ , i
177
+ &background_tasks_, &platform_workers_mutex ,
178
+ &platform_workers_ready , &pending_platform_workers , i
176
179
};
177
180
std::unique_ptr<uv_thread_t > t { new uv_thread_t () };
178
181
if (uv_thread_create (t.get (), BackgroundRunner, worker_data) != 0 )
@@ -182,8 +185,8 @@ BackgroundTaskRunner::BackgroundTaskRunner(int thread_pool_size) {
182
185
183
186
// Wait for platform workers to initialize before continuing with the
184
187
// bootstrap.
185
- while (pending_platform_workers_ > 0 ) {
186
- platform_workers_ready_ .Wait (lock);
188
+ while (pending_platform_workers > 0 ) {
189
+ platform_workers_ready .Wait (lock);
187
190
}
188
191
}
189
192
0 commit comments