Skip to content

Commit c67642a

Browse files
addaleaxBridgeAR
authored andcommitted
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>
1 parent b5dda32 commit c67642a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/node_watchdog.cc

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,20 @@ Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms, bool* timed_out)
3434
: isolate_(isolate), timed_out_(timed_out) {
3535

3636
int rc;
37-
loop_ = new uv_loop_t;
38-
CHECK(loop_);
39-
rc = uv_loop_init(loop_);
37+
rc = uv_loop_init(&loop_);
4038
if (rc != 0) {
4139
FatalError("node::Watchdog::Watchdog()",
4240
"Failed to initialize uv loop.");
4341
}
4442

45-
rc = uv_async_init(loop_, &async_, [](uv_async_t* signal) {
43+
rc = uv_async_init(&loop_, &async_, [](uv_async_t* signal) {
4644
Watchdog* w = ContainerOf(&Watchdog::async_, signal);
47-
uv_stop(w->loop_);
45+
uv_stop(&w->loop_);
4846
});
4947

5048
CHECK_EQ(0, rc);
5149

52-
rc = uv_timer_init(loop_, &timer_);
50+
rc = uv_timer_init(&loop_, &timer_);
5351
CHECK_EQ(0, rc);
5452

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

6967
// UV_RUN_DEFAULT so that libuv has a chance to clean up.
70-
uv_run(loop_, UV_RUN_DEFAULT);
68+
uv_run(&loop_, UV_RUN_DEFAULT);
7169

72-
CheckedUvLoopClose(loop_);
73-
delete loop_;
74-
loop_ = nullptr;
70+
CheckedUvLoopClose(&loop_);
7571
}
7672

7773

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

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

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

9793

src/node_watchdog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Watchdog {
4949

5050
v8::Isolate* isolate_;
5151
uv_thread_t thread_;
52-
uv_loop_t* loop_;
52+
uv_loop_t loop_;
5353
uv_async_t async_;
5454
uv_timer_t timer_;
5555
bool* timed_out_;

0 commit comments

Comments
 (0)