src: do not use pointer for loop in node_watchdog
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
5872705796
commit
25399e4c9c
@ -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_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user