Skip to content

Commit e63e4a1

Browse files
addaleaxMylesBorins
authored andcommitted
src: remove async_hooks destroy timer handle
PR-URL: #17117 Reviewed-By: James M Snell <[email protected]>
1 parent e1f0846 commit e63e4a1

File tree

5 files changed

+10
-32
lines changed

5 files changed

+10
-32
lines changed

src/async_wrap.cc

+2-7
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local<Value> wrapper) {
137137
// end RetainedAsyncInfo
138138

139139

140-
static void DestroyAsyncIdsCallback(uv_timer_t* handle) {
141-
Environment* env = Environment::from_destroy_async_ids_timer_handle(handle);
142-
143-
HandleScope handle_scope(env->isolate());
144-
Context::Scope context_scope(env->context());
140+
static void DestroyAsyncIdsCallback(Environment* env, void* data) {
145141
Local<Function> fn = env->async_hooks_destroy_function();
146142

147143
FatalTryCatch try_catch(env);
@@ -668,8 +664,7 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) {
668664
return;
669665

670666
if (env->destroy_async_id_list()->empty()) {
671-
uv_timer_start(env->destroy_async_ids_timer_handle(),
672-
DestroyAsyncIdsCallback, 0, 0);
667+
env->SetImmediate(DestroyAsyncIdsCallback, nullptr);
673668
}
674669

675670
env->destroy_async_id_list()->push_back(async_id);

src/env-inl.h

-9
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
349349
return &immediate_idle_handle_;
350350
}
351351

352-
inline Environment* Environment::from_destroy_async_ids_timer_handle(
353-
uv_timer_t* handle) {
354-
return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle);
355-
}
356-
357-
inline uv_timer_t* Environment::destroy_async_ids_timer_handle() {
358-
return &destroy_async_ids_timer_handle_;
359-
}
360-
361352
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
362353
HandleCleanupCb cb,
363354
void *arg) {

src/env.cc

-6
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ void Environment::Start(int argc,
9494
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
9595
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
9696

97-
uv_timer_init(event_loop(), destroy_async_ids_timer_handle());
98-
9997
auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) {
10098
handle->data = env;
10199

@@ -120,10 +118,6 @@ void Environment::Start(int argc,
120118
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
121119
close_and_finish,
122120
nullptr);
123-
RegisterHandleCleanup(
124-
reinterpret_cast<uv_handle_t*>(&destroy_async_ids_timer_handle_),
125-
close_and_finish,
126-
nullptr);
127121

128122
if (start_profiler_idle_notifier) {
129123
StartProfilerIdleNotifier();

src/env.h

-4
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,8 @@ class Environment {
542542
inline uint32_t watched_providers() const;
543543

544544
static inline Environment* from_immediate_check_handle(uv_check_t* handle);
545-
static inline Environment* from_destroy_async_ids_timer_handle(
546-
uv_timer_t* handle);
547545
inline uv_check_t* immediate_check_handle();
548546
inline uv_idle_t* immediate_idle_handle();
549-
inline uv_timer_t* destroy_async_ids_timer_handle();
550547

551548
// Register clean-up cb to be called on environment destruction.
552549
inline void RegisterHandleCleanup(uv_handle_t* handle,
@@ -693,7 +690,6 @@ class Environment {
693690
IsolateData* const isolate_data_;
694691
uv_check_t immediate_check_handle_;
695692
uv_idle_t immediate_idle_handle_;
696-
uv_timer_t destroy_async_ids_timer_handle_;
697693
uv_prepare_t idle_prepare_handle_;
698694
uv_check_t idle_check_handle_;
699695

test/async-hooks/test-signalwrap.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ function onsigusr2() {
6666
}
6767

6868
function onsigusr2Again() {
69-
checkInvocations(
70-
signal1, { init: 1, before: 2, after: 2, destroy: 1 },
71-
'signal1: when second SIGUSR2 handler is called');
72-
checkInvocations(
73-
signal2, { init: 1, before: 1 },
74-
'signal2: when second SIGUSR2 handler is called');
69+
setImmediate(() => {
70+
checkInvocations(
71+
signal1, { init: 1, before: 2, after: 2, destroy: 1 },
72+
'signal1: when second SIGUSR2 handler is called');
73+
checkInvocations(
74+
signal2, { init: 1, before: 1 },
75+
'signal2: when second SIGUSR2 handler is called');
76+
});
7577
}
7678

7779
process.on('exit', onexit);

0 commit comments

Comments
 (0)