From 084c3796483a15da102480b2c5a1496417b5d7cf Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 12 Nov 2019 19:36:07 +0000 Subject: [PATCH] src: associate is_main_thread() with worker_context() In our codebase, the assumption generally is that `!is_main_thread()` means that the current Environment belongs to a Node.js Worker thread. PR-URL: https://github.com/nodejs/node/pull/30467 Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- src/api/environment.cc | 3 +-- src/env-inl.h | 2 +- src/env.h | 1 - src/node_main_instance.cc | 3 +-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/api/environment.cc b/src/api/environment.cc index 23bae50d6da7ab..5afb5420fc0895 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -345,8 +345,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data, context, args, exec_args, - static_cast(Environment::kIsMainThread | - Environment::kOwnsProcessState | + static_cast(Environment::kOwnsProcessState | Environment::kOwnsInspector)); env->InitializeLibuv(per_process::v8_is_profiling); if (env->RunBootstrapping().IsEmpty()) { diff --git a/src/env-inl.h b/src/env-inl.h index 3969969a970f62..b0af5bfcbdc473 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -889,7 +889,7 @@ inline void Environment::set_has_serialized_options(bool value) { } inline bool Environment::is_main_thread() const { - return flags_ & kIsMainThread; + return worker_context() == nullptr; } inline bool Environment::owns_process_state() const { diff --git a/src/env.h b/src/env.h index 0007142232a2d0..e4ce0599089a5f 100644 --- a/src/env.h +++ b/src/env.h @@ -859,7 +859,6 @@ class Environment : public MemoryRetainer { enum Flags { kNoFlags = 0, - kIsMainThread = 1 << 0, kOwnsProcessState = 1 << 1, kOwnsInspector = 1 << 2, }; diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 831ba528284a52..643041571fb5f3 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -207,8 +207,7 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code) { context, args_, exec_args_, - static_cast(Environment::kIsMainThread | - Environment::kOwnsProcessState | + static_cast(Environment::kOwnsProcessState | Environment::kOwnsInspector)) }; env->InitializeLibuv(per_process::v8_is_profiling); env->InitializeDiagnostics();