From f49cef549c652945a119bc265d0e1675cfb26e2c Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 8 Dec 2020 12:06:52 +0100 Subject: [PATCH] src: add typedef for CleanupHookCallback callback This commit adds a typedef for the callback parameter used in CleanupHookCallback's constructor, AddCleanupHook, and RemoveCleanupHook. PR-URL: https://github.com/nodejs/node/pull/36442 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Rich Trott --- src/env-inl.h | 4 ++-- src/env.h | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 3dd0e372ecab18..cd9f6daaaff758 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -1024,7 +1024,7 @@ inline void Environment::SetInstanceMethod(v8::Local that, t->SetClassName(name_string); } -void Environment::AddCleanupHook(void (*fn)(void*), void* arg) { +void Environment::AddCleanupHook(CleanupCallback fn, void* arg) { auto insertion_info = cleanup_hooks_.emplace(CleanupHookCallback { fn, arg, cleanup_hook_counter_++ }); @@ -1032,7 +1032,7 @@ void Environment::AddCleanupHook(void (*fn)(void*), void* arg) { CHECK_EQ(insertion_info.second, true); } -void Environment::RemoveCleanupHook(void (*fn)(void*), void* arg) { +void Environment::RemoveCleanupHook(CleanupCallback fn, void* arg) { CleanupHookCallback search { fn, arg, 0 }; cleanup_hooks_.erase(search); } diff --git a/src/env.h b/src/env.h index d2b506523517f7..a0d59ff8728deb 100644 --- a/src/env.h +++ b/src/env.h @@ -891,7 +891,9 @@ class ShouldNotAbortOnUncaughtScope { class CleanupHookCallback { public: - CleanupHookCallback(void (*fn)(void*), + typedef void (*Callback)(void*); + + CleanupHookCallback(Callback fn, void* arg, uint64_t insertion_order_counter) : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {} @@ -911,7 +913,7 @@ class CleanupHookCallback { private: friend class Environment; - void (*fn_)(void*); + Callback fn_; void* arg_; // We keep track of the insertion order for these objects, so that we can @@ -1316,8 +1318,9 @@ class Environment : public MemoryRetainer { void ScheduleTimer(int64_t duration); void ToggleTimerRef(bool ref); - inline void AddCleanupHook(void (*fn)(void*), void* arg); - inline void RemoveCleanupHook(void (*fn)(void*), void* arg); + using CleanupCallback = CleanupHookCallback::Callback; + inline void AddCleanupHook(CleanupCallback cb, void* arg); + inline void RemoveCleanupHook(CleanupCallback cb, void* arg); void RunCleanup(); static size_t NearHeapLimitCallback(void* data,