Skip to content

Commit

Permalink
src: use std::list for at_exit_functions
Browse files Browse the repository at this point in the history
This change was suggested by bnoordhuis in the following comment:
nodejs/node#9163 (comment)

Not including any tests as this is covered by test/addons/at-exit.

PR-URL: nodejs/node#12255
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
danbev authored and andrew749 committed Jul 19, 2017
1 parent 471a85d commit f796270
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#include <string>
#include <vector>
#include <list>

#if defined(NODE_HAVE_I18N_SUPPORT)
#include <unicode/uvernum.h>
Expand Down Expand Up @@ -4429,34 +4430,24 @@ void Init(int* argc,


struct AtExitCallback {
AtExitCallback* next_;
void (*cb_)(void* arg);
void* arg_;
};

static AtExitCallback* at_exit_functions_;
static std::list<AtExitCallback> at_exit_functions;


// TODO(bnoordhuis) Turn into per-context event.
void RunAtExit(Environment* env) {
AtExitCallback* p = at_exit_functions_;
at_exit_functions_ = nullptr;

while (p) {
AtExitCallback* q = p->next_;
p->cb_(p->arg_);
delete p;
p = q;
for (AtExitCallback at_exit : at_exit_functions) {
at_exit.cb_(at_exit.arg_);
}
at_exit_functions.clear();
}


void AtExit(void (*cb)(void* arg), void* arg) {
AtExitCallback* p = new AtExitCallback;
p->cb_ = cb;
p->arg_ = arg;
p->next_ = at_exit_functions_;
at_exit_functions_ = p;
at_exit_functions.push_back(AtExitCallback{cb, arg});
}


Expand Down

0 comments on commit f796270

Please sign in to comment.