Skip to content
Permalink
Browse files

src: do not use pointer for loop in node_watchdog

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 BridgeAR committed Jun 2, 2019
1 parent b5dda32 commit c67642ae031816a2087acc362d45a51b0dc94782
Showing with 9 additions and 13 deletions.
  1. +8 −12 src/node_watchdog.cc
  2. +1 −1 src/node_watchdog.h
@@ -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);
@@ -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_);
}


@@ -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_
@@ -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_);
}


@@ -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_;

0 comments on commit c67642a

Please sign in to comment.
You can’t perform that action at this time.