From e63e4a1facf14df16c072cdadfe530010a8d3920 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 18 Nov 2017 14:54:06 +0100 Subject: [PATCH] src: remove async_hooks destroy timer handle PR-URL: https://github.com/nodejs/node/pull/17117 Reviewed-By: James M Snell --- src/async_wrap.cc | 9 ++------- src/env-inl.h | 9 --------- src/env.cc | 6 ------ src/env.h | 4 ---- test/async-hooks/test-signalwrap.js | 14 ++++++++------ 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 607d4792192d18..3f77169321a919 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -137,11 +137,7 @@ RetainedObjectInfo* WrapperInfo(uint16_t class_id, Local wrapper) { // end RetainedAsyncInfo -static void DestroyAsyncIdsCallback(uv_timer_t* handle) { - Environment* env = Environment::from_destroy_async_ids_timer_handle(handle); - - HandleScope handle_scope(env->isolate()); - Context::Scope context_scope(env->context()); +static void DestroyAsyncIdsCallback(Environment* env, void* data) { Local fn = env->async_hooks_destroy_function(); FatalTryCatch try_catch(env); @@ -668,8 +664,7 @@ void AsyncWrap::EmitDestroy(Environment* env, double async_id) { return; if (env->destroy_async_id_list()->empty()) { - uv_timer_start(env->destroy_async_ids_timer_handle(), - DestroyAsyncIdsCallback, 0, 0); + env->SetImmediate(DestroyAsyncIdsCallback, nullptr); } env->destroy_async_id_list()->push_back(async_id); diff --git a/src/env-inl.h b/src/env-inl.h index 34ba028dba1524..2be6580ca88124 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -349,15 +349,6 @@ inline uv_idle_t* Environment::immediate_idle_handle() { return &immediate_idle_handle_; } -inline Environment* Environment::from_destroy_async_ids_timer_handle( - uv_timer_t* handle) { - return ContainerOf(&Environment::destroy_async_ids_timer_handle_, handle); -} - -inline uv_timer_t* Environment::destroy_async_ids_timer_handle() { - return &destroy_async_ids_timer_handle_; -} - inline void Environment::RegisterHandleCleanup(uv_handle_t* handle, HandleCleanupCb cb, void *arg) { diff --git a/src/env.cc b/src/env.cc index 508fe3458ce24a..8f8255819b4a28 100644 --- a/src/env.cc +++ b/src/env.cc @@ -94,8 +94,6 @@ void Environment::Start(int argc, uv_unref(reinterpret_cast(&idle_prepare_handle_)); uv_unref(reinterpret_cast(&idle_check_handle_)); - uv_timer_init(event_loop(), destroy_async_ids_timer_handle()); - auto close_and_finish = [](Environment* env, uv_handle_t* handle, void* arg) { handle->data = env; @@ -120,10 +118,6 @@ void Environment::Start(int argc, reinterpret_cast(&idle_check_handle_), close_and_finish, nullptr); - RegisterHandleCleanup( - reinterpret_cast(&destroy_async_ids_timer_handle_), - close_and_finish, - nullptr); if (start_profiler_idle_notifier) { StartProfilerIdleNotifier(); diff --git a/src/env.h b/src/env.h index 24aa22c695b73c..0b71007faafbc7 100644 --- a/src/env.h +++ b/src/env.h @@ -542,11 +542,8 @@ class Environment { inline uint32_t watched_providers() const; static inline Environment* from_immediate_check_handle(uv_check_t* handle); - static inline Environment* from_destroy_async_ids_timer_handle( - uv_timer_t* handle); inline uv_check_t* immediate_check_handle(); inline uv_idle_t* immediate_idle_handle(); - inline uv_timer_t* destroy_async_ids_timer_handle(); // Register clean-up cb to be called on environment destruction. inline void RegisterHandleCleanup(uv_handle_t* handle, @@ -693,7 +690,6 @@ class Environment { IsolateData* const isolate_data_; uv_check_t immediate_check_handle_; uv_idle_t immediate_idle_handle_; - uv_timer_t destroy_async_ids_timer_handle_; uv_prepare_t idle_prepare_handle_; uv_check_t idle_check_handle_; diff --git a/test/async-hooks/test-signalwrap.js b/test/async-hooks/test-signalwrap.js index ff7d08bc1207b0..fa975ff0178f3c 100644 --- a/test/async-hooks/test-signalwrap.js +++ b/test/async-hooks/test-signalwrap.js @@ -66,12 +66,14 @@ function onsigusr2() { } function onsigusr2Again() { - checkInvocations( - signal1, { init: 1, before: 2, after: 2, destroy: 1 }, - 'signal1: when second SIGUSR2 handler is called'); - checkInvocations( - signal2, { init: 1, before: 1 }, - 'signal2: when second SIGUSR2 handler is called'); + setImmediate(() => { + checkInvocations( + signal1, { init: 1, before: 2, after: 2, destroy: 1 }, + 'signal1: when second SIGUSR2 handler is called'); + checkInvocations( + signal2, { init: 1, before: 1 }, + 'signal2: when second SIGUSR2 handler is called'); + }); } process.on('exit', onexit);