Skip to content

Commit 4b9914a

Browse files
danbevMylesBorins
authored andcommitted
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: #19226 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b8ca616 commit 4b9914a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/env.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,25 @@ void Environment::PrintSyncTrace() const {
218218
}
219219

220220
void Environment::RunBeforeExitCallbacks() {
221-
for (BeforeExitCallback before_exit : before_exit_functions_) {
221+
for (ExitCallback before_exit : before_exit_functions_) {
222222
before_exit.cb_(before_exit.arg_);
223223
}
224224
before_exit_functions_.clear();
225225
}
226226

227227
void Environment::BeforeExit(void (*cb)(void* arg), void* arg) {
228-
before_exit_functions_.push_back(BeforeExitCallback{cb, arg});
228+
before_exit_functions_.push_back(ExitCallback{cb, arg});
229229
}
230230

231231
void Environment::RunAtExitCallbacks() {
232-
for (AtExitCallback at_exit : at_exit_functions_) {
232+
for (ExitCallback at_exit : at_exit_functions_) {
233233
at_exit.cb_(at_exit.arg_);
234234
}
235235
at_exit_functions_.clear();
236236
}
237237

238238
void Environment::AtExit(void (*cb)(void* arg), void* arg) {
239-
at_exit_functions_.push_back(AtExitCallback{cb, arg});
239+
at_exit_functions_.push_back(ExitCallback{cb, arg});
240240
}
241241

242242
void Environment::AddPromiseHook(promise_hook_func fn, void* arg) {

src/env.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,13 @@ class Environment {
799799

800800
double* fs_stats_field_array_;
801801

802-
struct BeforeExitCallback {
802+
struct ExitCallback {
803803
void (*cb_)(void* arg);
804804
void* arg_;
805805
};
806-
std::list<BeforeExitCallback> before_exit_functions_;
806+
std::list<ExitCallback> before_exit_functions_;
807807

808-
struct AtExitCallback {
809-
void (*cb_)(void* arg);
810-
void* arg_;
811-
};
812-
std::list<AtExitCallback> at_exit_functions_;
808+
std::list<ExitCallback> at_exit_functions_;
813809

814810
struct PromiseHookCallback {
815811
promise_hook_func cb_;

0 commit comments

Comments
 (0)