Skip to content

Commit

Permalink
src: associate is_main_thread() with worker_context()
Browse files Browse the repository at this point in the history
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: #30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
addaleax committed Mar 21, 2020
1 parent 64c0122 commit 084c379
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
context,
args,
exec_args,
static_cast<Environment::Flags>(Environment::kIsMainThread |
Environment::kOwnsProcessState |
static_cast<Environment::Flags>(Environment::kOwnsProcessState |
Environment::kOwnsInspector));
env->InitializeLibuv(per_process::v8_is_profiling);
if (env->RunBootstrapping().IsEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,6 @@ class Environment : public MemoryRetainer {

enum Flags {
kNoFlags = 0,
kIsMainThread = 1 << 0,
kOwnsProcessState = 1 << 1,
kOwnsInspector = 1 << 2,
};
Expand Down
3 changes: 1 addition & 2 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code) {
context,
args_,
exec_args_,
static_cast<Environment::Flags>(Environment::kIsMainThread |
Environment::kOwnsProcessState |
static_cast<Environment::Flags>(Environment::kOwnsProcessState |
Environment::kOwnsInspector)) };
env->InitializeLibuv(per_process::v8_is_profiling);
env->InitializeDiagnostics();
Expand Down

0 comments on commit 084c379

Please sign in to comment.