From 58ba8bfc46c06bf9f75887c18df563d91a1f782c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 8 Feb 2019 19:22:35 +0100 Subject: worker: pre-allocate thread id Allocate a thread id before actually creating the Environment instance. PR-URL: https://github.com/nodejs/node/pull/26011 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Ben Noordhuis Reviewed-By: Gireesh Punathil Reviewed-By: Joyee Cheung --- src/node_worker.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/node_worker.cc') diff --git a/src/node_worker.cc b/src/node_worker.cc index 3fd19de97c..36b4106d13 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -71,7 +71,8 @@ Worker::Worker(Environment* env, Local wrap, const std::string& url, std::shared_ptr per_isolate_opts) - : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_WORKER), url_(url) { + : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_WORKER), url_(url), + thread_id_(Environment::AllocateThreadId()) { Debug(this, "Creating new worker instance at %p", static_cast(this)); // Set up everything that needs to be set up in the parent environment. @@ -114,11 +115,11 @@ Worker::Worker(Environment* env, Context::Scope context_scope(context); // TODO(addaleax): Use CreateEnvironment(), or generally another public API. - env_.reset(new Environment(isolate_data_.get(), context)); + env_.reset(new Environment( + isolate_data_.get(), context, Flags::kNoFlags, thread_id_)); CHECK_NOT_NULL(env_); env_->set_abort_on_uncaught_exception(false); env_->set_worker_context(this); - thread_id_ = env_->thread_id(); env_->Start(env->profiler_idle_notifier_started()); env_->ProcessCliArgs(std::vector{}, -- cgit v1.2.3