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.

Backport-PR-URL: #35241
PR-URL: #30467
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
addaleax committed Sep 23, 2020
1 parent b7350e8 commit e809a5c
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 @@ -332,8 +332,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 @@ -854,7 +854,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 @@ -876,7 +876,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 @@ -204,8 +204,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 e809a5c

Please sign in to comment.