Skip to content

Commit 2847ab2

Browse files
addaleaxtargos
authored andcommitted
src: remove loop_init_failed_ from Worker class
There’s no reason for this to not be stored alongside the loop data structure itself. PR-URL: nodejs#32562 Refs: nodejs#32344 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fa41f32 commit 2847ab2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/node_worker.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ class WorkerThreadData {
145145
uv_err_name_r(ret, err_buf, sizeof(err_buf));
146146
w->custom_error_ = "ERR_WORKER_INIT_FAILED";
147147
w->custom_error_str_ = err_buf;
148-
w->loop_init_failed_ = true;
149148
w->stopped_ = true;
150149
return;
151150
}
151+
loop_init_failed_ = false;
152152

153153
Isolate::CreateParams params;
154154
SetIsolateCreateParamsForNode(&params);
@@ -201,6 +201,7 @@ class WorkerThreadData {
201201
}
202202

203203
if (isolate != nullptr) {
204+
CHECK(!loop_init_failed_);
204205
bool platform_finished = false;
205206

206207
isolate_data_.reset();
@@ -219,18 +220,20 @@ class WorkerThreadData {
219220

220221
// Wait until the platform has cleaned up all relevant resources.
221222
while (!platform_finished) {
222-
CHECK(!w_->loop_init_failed_);
223223
uv_run(&loop_, UV_RUN_ONCE);
224224
}
225225
}
226-
if (!w_->loop_init_failed_) {
226+
if (!loop_init_failed_) {
227227
CheckedUvLoopClose(&loop_);
228228
}
229229
}
230230

231+
bool loop_is_usable() const { return !loop_init_failed_; }
232+
231233
private:
232234
Worker* const w_;
233235
uv_loop_t loop_;
236+
bool loop_init_failed_ = true;
234237
DeleteFnPtr<IsolateData, FreeIsolateData> isolate_data_;
235238

236239
friend class Worker;
@@ -260,7 +263,7 @@ void Worker::Run() {
260263

261264
WorkerThreadData data(this);
262265
if (isolate_ == nullptr) return;
263-
CHECK(!data.w_->loop_init_failed_);
266+
CHECK(data.loop_is_usable());
264267

265268
Debug(this, "Starting worker with id %llu", thread_id_);
266269
{

src/node_worker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ class Worker : public AsyncWrap {
8888
bool thread_joined_ = true;
8989
const char* custom_error_ = nullptr;
9090
std::string custom_error_str_;
91-
bool loop_init_failed_ = false;
9291
int exit_code_ = 0;
9392
uint64_t thread_id_ = -1;
9493
uintptr_t stack_base_ = 0;

0 commit comments

Comments
 (0)