src: avoid duplicate Before/AtExitCallback structs
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: https://github.com/nodejs/node/pull/19226 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
695590e386
commit
e16a2be8d8
@ -293,25 +293,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) {
|
||||
|
10
src/env.h
10
src/env.h
@ -823,17 +823,13 @@ class Environment {
|
||||
static const int kFsStatsFieldsLength = 2 * 14;
|
||||
AliasedBuffer<double, v8::Float64Array> 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_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user