Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: do not use pointer for loop in node_watchdog #28020

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions src/node_watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms, bool* timed_out)
: isolate_(isolate), timed_out_(timed_out) {

int rc;
loop_ = new uv_loop_t;
CHECK(loop_);
rc = uv_loop_init(loop_);
rc = uv_loop_init(&loop_);
if (rc != 0) {
FatalError("node::Watchdog::Watchdog()",
"Failed to initialize uv loop.");
}

rc = uv_async_init(loop_, &async_, [](uv_async_t* signal) {
rc = uv_async_init(&loop_, &async_, [](uv_async_t* signal) {
Watchdog* w = ContainerOf(&Watchdog::async_, signal);
uv_stop(w->loop_);
uv_stop(&w->loop_);
});

CHECK_EQ(0, rc);

rc = uv_timer_init(loop_, &timer_);
rc = uv_timer_init(&loop_, &timer_);
CHECK_EQ(0, rc);

rc = uv_timer_start(&timer_, &Watchdog::Timer, ms, 0);
Expand All @@ -67,11 +65,9 @@ Watchdog::~Watchdog() {
uv_close(reinterpret_cast<uv_handle_t*>(&async_), nullptr);

// UV_RUN_DEFAULT so that libuv has a chance to clean up.
uv_run(loop_, UV_RUN_DEFAULT);
uv_run(&loop_, UV_RUN_DEFAULT);

CheckedUvLoopClose(loop_);
delete loop_;
loop_ = nullptr;
CheckedUvLoopClose(&loop_);
}


Expand All @@ -80,7 +76,7 @@ void Watchdog::Run(void* arg) {

// UV_RUN_DEFAULT the loop will be stopped either by the async or the
// timer handle.
uv_run(wd->loop_, UV_RUN_DEFAULT);
uv_run(&wd->loop_, UV_RUN_DEFAULT);

// Loop ref count reaches zero when both handles are closed.
// Close the timer handle on this side and let ~Watchdog() close async_
Expand All @@ -91,7 +87,7 @@ void Watchdog::Timer(uv_timer_t* timer) {
Watchdog* w = ContainerOf(&Watchdog::timer_, timer);
*w->timed_out_ = true;
w->isolate()->TerminateExecution();
uv_stop(w->loop_);
uv_stop(&w->loop_);
}


Expand Down
2 changes: 1 addition & 1 deletion src/node_watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Watchdog {

v8::Isolate* isolate_;
uv_thread_t thread_;
uv_loop_t* loop_;
uv_loop_t loop_;
uv_async_t async_;
uv_timer_t timer_;
bool* timed_out_;
Expand Down