Skip to content

Commit 88403c4

Browse files
committed
src: remove async_hooks destroy timer handle
1 parent af5ba7b commit 88403c4

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

src/async_wrap.cc

Lines changed: 2 additions & 7 deletions
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
TryCatch try_catch(env->isolate());
@@ -689,8 +685,7 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) {
689685
return;
690686

691687
if (env->destroy_async_id_list()->empty()) {
692-
uv_timer_start(env->destroy_async_ids_timer_handle(),
693-
DestroyAsyncIdsCallback, 0, 0);
688+
env->SetImmediate(DestroyAsyncIdsCallback, nullptr);
694689
}
695690

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

src/env-inl.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() {
368368
return &immediate_idle_handle_;
369369
}
370370

371-
inline Environment* Environment::from_destroy_async_ids_timer_handle(
372-
uv_timer_t* handle) {
373-
return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle);
374-
}
375-
376-
inline uv_timer_t* Environment::destroy_async_ids_timer_handle() {
377-
return &destroy_async_ids_timer_handle_;
378-
}
379-
380371
inline void Environment::RegisterHandleCleanup(uv_handle_t* handle,
381372
HandleCleanupCb cb,
382373
void *arg) {

src/env.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ void Environment::Start(int argc,
102102
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_prepare_handle_));
103103
uv_unref(reinterpret_cast<uv_handle_t*>(&idle_check_handle_));
104104

105-
uv_timer_init(event_loop(), destroy_async_ids_timer_handle());
106-
107105
auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) {
108106
handle->data = env;
109107

@@ -128,10 +126,6 @@ void Environment::Start(int argc,
128126
reinterpret_cast<uv_handle_t*>(&idle_check_handle_),
129127
close_and_finish,
130128
nullptr);
131-
RegisterHandleCleanup(
132-
reinterpret_cast<uv_handle_t*>(&destroy_async_ids_timer_handle_),
133-
close_and_finish,
134-
nullptr);
135129

136130
if (start_profiler_idle_notifier) {
137131
StartProfilerIdleNotifier();

src/env.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,8 @@ class Environment {
564564
inline uint32_t watched_providers() const;
565565

566566
static inline Environment* from_immediate_check_handle(uv_check_t* handle);
567-
static inline Environment* from_destroy_async_ids_timer_handle(
568-
uv_timer_t* handle);
569567
inline uv_check_t* immediate_check_handle();
570568
inline uv_idle_t* immediate_idle_handle();
571-
inline uv_timer_t* destroy_async_ids_timer_handle();
572569

573570
// Register clean-up cb to be called on environment destruction.
574571
inline void RegisterHandleCleanup(uv_handle_t* handle,
@@ -722,7 +719,6 @@ class Environment {
722719
IsolateData* const isolate_data_;
723720
uv_check_t immediate_check_handle_;
724721
uv_idle_t immediate_idle_handle_;
725-
uv_timer_t destroy_async_ids_timer_handle_;
726722
uv_prepare_t idle_prepare_handle_;
727723
uv_check_t idle_check_handle_;
728724

test/async-hooks/test-signalwrap.js

Lines changed: 8 additions & 6 deletions
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);

test/async-hooks/test-tcpwrap.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ function onconnection(c) {
128128
function onserverClosed() {
129129
checkInvocations(tcp1, { init: 1, before: 1, after: 1, destroy: 1 },
130130
'tcp1 when server is closed');
131-
checkInvocations(tcp2, { init: 1, before: 2, after: 2, destroy: 1 },
132-
'tcp2 when server is closed');
131+
setImmediate(() => {
132+
checkInvocations(tcp2, { init: 1, before: 2, after: 2, destroy: 1 },
133+
'tcp2 after server is closed');
134+
});
133135
checkInvocations(tcp3, { init: 1, before: 1, after: 1 },
134136
'tcp3 synchronously when server is closed');
135137
tick(2, () => {

0 commit comments

Comments
 (0)