From c67642ae031816a2087acc362d45a51b0dc94782 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 2 Jun 2019 15:28:55 +0200 Subject: [PATCH] src: do not use pointer for loop in node_watchdog PR-URL: https://github.com/nodejs/node/pull/28020 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Rich Trott --- src/node_watchdog.cc | 20 ++++++++------------ src/node_watchdog.h | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc index 0c055489fcff68..e0f606c949a009 100644 --- a/src/node_watchdog.cc +++ b/src/node_watchdog.cc @@ -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(&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_); } diff --git a/src/node_watchdog.h b/src/node_watchdog.h index 9c56b90e9ee431..64b1165d16f222 100644 --- a/src/node_watchdog.h +++ b/src/node_watchdog.h @@ -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_;