Use atexit() instead of onexit()
This commit is contained in:
parent
c1021b9943
commit
4d3d6c9168
1 changed files with 13 additions and 5 deletions
|
@ -8,6 +8,9 @@
|
||||||
// Local includes.
|
// Local includes.
|
||||||
#include "another_memcheck.h"
|
#include "another_memcheck.h"
|
||||||
|
|
||||||
|
// Function declaration.
|
||||||
|
void exit_handler_stats();
|
||||||
|
|
||||||
namespace SC_AM_Internal {
|
namespace SC_AM_Internal {
|
||||||
Stats *stats = nullptr;
|
Stats *stats = nullptr;
|
||||||
int is_env_status = 0;
|
int is_env_status = 0;
|
||||||
|
@ -95,11 +98,7 @@ namespace SC_AM_Internal {
|
||||||
void *unused = new(recursive_mutex) std::recursive_mutex{};
|
void *unused = new(recursive_mutex) std::recursive_mutex{};
|
||||||
(void)unused;
|
(void)unused;
|
||||||
|
|
||||||
on_exit([] ([[maybe_unused]] int status, void *ptr) {
|
std::atexit(exit_handler_stats);
|
||||||
Stats *stats = reinterpret_cast<Stats*>(ptr);
|
|
||||||
stats->print_status();
|
|
||||||
stats->cleanup();
|
|
||||||
}, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stats::cleanup() {
|
void Stats::cleanup() {
|
||||||
|
@ -218,4 +217,13 @@ namespace SC_AM_Internal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function definition.
|
||||||
|
void exit_handler_stats() {
|
||||||
|
if (SC_AM_Internal::stats != nullptr) {
|
||||||
|
SC_AM_Internal::stats->print_status();
|
||||||
|
SC_AM_Internal::stats->cleanup();
|
||||||
|
SC_AM_Internal::stats = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// vim: et sw=2 ts=2 sts=2
|
// vim: et sw=2 ts=2 sts=2
|
||||||
|
|
Loading…
Reference in a new issue