Skip to content

Commit

Permalink
src: avoid duplicate Before/AtExitCallback structs
Browse files Browse the repository at this point in the history
Currently, BeforeExitCallback and AtExitCallback are identical apart for
the name of the struct. This commit introduces an ExitCallback struct
with can be used in both cases to avoid the duplication.

PR-URL: #19226
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
danbev authored and MylesBorins committed Mar 20, 2018
1 parent b8ca616 commit 4b9914a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,25 @@ void Environment::PrintSyncTrace() const {
}

void Environment::RunBeforeExitCallbacks() {
for (BeforeExitCallback before_exit : before_exit_functions_) {
for (ExitCallback before_exit : before_exit_functions_) {
before_exit.cb_(before_exit.arg_);
}
before_exit_functions_.clear();
}

void Environment::BeforeExit(void (*cb)(void* arg), void* arg) {
before_exit_functions_.push_back(BeforeExitCallback{cb, arg});
before_exit_functions_.push_back(ExitCallback{cb, arg});
}

void Environment::RunAtExitCallbacks() {
for (AtExitCallback at_exit : at_exit_functions_) {
for (ExitCallback at_exit : at_exit_functions_) {
at_exit.cb_(at_exit.arg_);
}
at_exit_functions_.clear();
}

void Environment::AtExit(void (*cb)(void* arg), void* arg) {
at_exit_functions_.push_back(AtExitCallback{cb, arg});
at_exit_functions_.push_back(ExitCallback{cb, arg});
}

void Environment::AddPromiseHook(promise_hook_func fn, void* arg) {
Expand Down
10 changes: 3 additions & 7 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,17 +799,13 @@ class Environment {

double* fs_stats_field_array_;

struct BeforeExitCallback {
struct ExitCallback {
void (*cb_)(void* arg);
void* arg_;
};
std::list<BeforeExitCallback> before_exit_functions_;
std::list<ExitCallback> before_exit_functions_;

struct AtExitCallback {
void (*cb_)(void* arg);
void* arg_;
};
std::list<AtExitCallback> at_exit_functions_;
std::list<ExitCallback> at_exit_functions_;

struct PromiseHookCallback {
promise_hook_func cb_;
Expand Down

0 comments on commit 4b9914a

Please sign in to comment.