Skip to content

Commit e809a5c

Browse files
committed
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. Backport-PR-URL: #35241 PR-URL: #30467 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent b7350e8 commit e809a5c

File tree

4 files changed

+3
-6
lines changed

4 files changed

+3
-6
lines changed

src/api/environment.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
332332
context,
333333
args,
334334
exec_args,
335-
static_cast<Environment::Flags>(Environment::kIsMainThread |
336-
Environment::kOwnsProcessState |
335+
static_cast<Environment::Flags>(Environment::kOwnsProcessState |
337336
Environment::kOwnsInspector));
338337
env->InitializeLibuv(per_process::v8_is_profiling);
339338
if (env->RunBootstrapping().IsEmpty()) {

src/env-inl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ inline void Environment::set_has_serialized_options(bool value) {
854854
}
855855

856856
inline bool Environment::is_main_thread() const {
857-
return flags_ & kIsMainThread;
857+
return worker_context() == nullptr;
858858
}
859859

860860
inline bool Environment::owns_process_state() const {

src/env.h

-1
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,6 @@ class Environment : public MemoryRetainer {
876876

877877
enum Flags {
878878
kNoFlags = 0,
879-
kIsMainThread = 1 << 0,
880879
kOwnsProcessState = 1 << 1,
881880
kOwnsInspector = 1 << 2,
882881
};

src/node_main_instance.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code) {
204204
context,
205205
args_,
206206
exec_args_,
207-
static_cast<Environment::Flags>(Environment::kIsMainThread |
208-
Environment::kOwnsProcessState |
207+
static_cast<Environment::Flags>(Environment::kOwnsProcessState |
209208
Environment::kOwnsInspector)) };
210209
env->InitializeLibuv(per_process::v8_is_profiling);
211210
env->InitializeDiagnostics();

0 commit comments

Comments
 (0)