diff options
author | Ali Ijaz Sheikh <ofrobots@google.com> | 2018-10-11 08:23:33 +0300 |
---|---|---|
committer | Ali Ijaz Sheikh <ofrobots@google.com> | 2018-10-13 08:30:53 +0300 |
commit | 9f7e3a404096db60438f6dc305b0a5fa4ecddae7 (patch) | |
tree | 3b78a22ff255766b40e14eddf02dc7a1874ca28e /src/node_platform.cc | |
parent | c24e9633fbc72fc8e0f8b6d1e93a2f30b884791c (diff) |
src: reduce platform worker barrier lifetime
Minor cleanup in the lifetime for the platform worker initialization
synchronization barrier.
PR-URL: https://github.com/nodejs/node/pull/23419
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_platform.cc')
-rw-r--r-- | src/node_platform.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/node_platform.cc b/src/node_platform.cc index 372a76fabe8..047cb432689 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -167,8 +167,11 @@ 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_)); @@ -176,8 +179,8 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) { 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, @@ -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); } } |