Skip to content

Commit

Permalink
src: reduce platform worker barrier lifetime
Browse files Browse the repository at this point in the history
Minor cleanup in the lifetime for the platform worker initialization
synchronization barrier.

PR-URL: #23419
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Denys Otrishko <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
ofrobots committed Oct 13, 2018
1 parent c24e963 commit 9f7e3a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 9 additions & 6 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,20 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {
};

WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) {
Mutex::ScopedLock lock(platform_workers_mutex_);
pending_platform_workers_ = thread_pool_size;
Mutex platform_workers_mutex;
ConditionVariable platform_workers_ready;

Mutex::ScopedLock lock(platform_workers_mutex);
int pending_platform_workers = thread_pool_size;

delayed_task_scheduler_.reset(
new DelayedTaskScheduler(&pending_worker_tasks_));
threads_.push_back(delayed_task_scheduler_->Start());

for (int i = 0; i < thread_pool_size; i++) {
PlatformWorkerData* worker_data = new PlatformWorkerData{
&pending_worker_tasks_, &platform_workers_mutex_,
&platform_workers_ready_, &pending_platform_workers_, i
&pending_worker_tasks_, &platform_workers_mutex,
&platform_workers_ready, &pending_platform_workers, i
};
std::unique_ptr<uv_thread_t> t { new uv_thread_t() };
if (uv_thread_create(t.get(), PlatformWorkerThread,
Expand All @@ -189,8 +192,8 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) {

// Wait for platform workers to initialize before continuing with the
// bootstrap.
while (pending_platform_workers_ > 0) {
platform_workers_ready_.Wait(lock);
while (pending_platform_workers > 0) {
platform_workers_ready.Wait(lock);
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ class WorkerThreadsTaskRunner {
std::unique_ptr<DelayedTaskScheduler> delayed_task_scheduler_;

std::vector<std::unique_ptr<uv_thread_t>> threads_;

Mutex platform_workers_mutex_;
ConditionVariable platform_workers_ready_;
int pending_platform_workers_;
};

class NodePlatform : public MultiIsolatePlatform {
Expand Down

0 comments on commit 9f7e3a4

Please sign in to comment.