Skip to content

Commit

Permalink
src: add typedef for CleanupHookCallback callback
Browse files Browse the repository at this point in the history
This commit adds a typedef for the callback parameter used in
CleanupHookCallback's constructor, AddCleanupHook, and
RemoveCleanupHook.

PR-URL: #36442
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
danbev authored and targos committed May 1, 2021
1 parent 9ccf7db commit 3701e5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1041,15 +1041,15 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> 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_++
});
// Make sure there was no existing element with these values.
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);
}
Expand Down
11 changes: 7 additions & 4 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,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) {}
Expand All @@ -809,7 +811,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
Expand Down Expand Up @@ -1171,8 +1173,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 void BuildEmbedderGraph(v8::Isolate* isolate,
Expand Down

0 comments on commit 3701e5d

Please sign in to comment.