Skip to content

Commit

Permalink
src: do not use pointer for loop in node_watchdog
Browse files Browse the repository at this point in the history
PR-URL: #28020
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
addaleax authored and Trott committed Jun 13, 2019
1 parent 5872705 commit 25399e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
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

0 comments on commit 25399e4

Please sign in to comment.