GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: clean up worker thread creation code · nodejs/node@0faaa7c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_worker.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+14-17Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -609,16 +609,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
609609
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());
610610
Mutex::ScopedLock lock(w->mutex_);
611611

612-
// The object now owns the created thread and should not be garbage collected
613-
// until that finishes.
614-
w->ClearWeak();
615-
616-
w->env()->add_sub_worker_context(w);
617612
w->stopped_ = false;
618-
w->thread_joined_ = false;
619-
620-
if (w->has_ref_)
621-
w->env()->add_refs(1);
622613

623614
uv_thread_options_t thread_options;
624615
thread_options.flags = UV_THREAD_HAS_STACK_SIZE;
@@ -645,21 +636,27 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
645636
// implicitly delete w
646637
});
647638
}, static_cast<void*>(w));
648-
if (ret != 0) {
639+
640+
if (ret == 0) {
641+
// The object now owns the created thread and should not be garbage
642+
// collected until that finishes.
643+
w->ClearWeak();
644+
w->thread_joined_ = false;
645+
646+
if (w->has_ref_)
647+
w->env()->add_refs(1);
648+
649+
w->env()->add_sub_worker_context(w);
650+
} else {
651+
w->stopped_ = true;
652+
649653
char err_buf[128];
650654
uv_err_name_r(ret, err_buf, sizeof(err_buf));
651-
w->custom_error_ = "ERR_WORKER_INIT_FAILED";
652-
w->custom_error_str_ = err_buf;
653-
w->loop_init_failed_ = true;
654-
w->thread_joined_ = true;
655-
w->stopped_ = true;
656-
w->env()->remove_sub_worker_context(w);
657655
{
658656
Isolate* isolate = w->env()->isolate();
659657
HandleScope handle_scope(isolate);
660658
THROW_ERR_WORKER_INIT_FAILED(isolate, err_buf);
661659
}
662-
w->MakeWeak();
663660
}
664661
}
665662

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.