Add atexit handler

This commit is contained in:
Patrick Lipka 2025-08-07 17:19:53 +02:00
parent 90acb142df
commit 6fb8bfefc6
1 changed files with 16 additions and 0 deletions

View File

@ -1,5 +1,18 @@
#include "rvprof_internal.h"
static void rvprof_atexit_handler(void){
if(g_rvprof.initialized) rvprof_context_cleanup();
}
static void register_atexit_handler(void){
static int registered = 0;
if (!registered){
atexit(rvprof_atexit_handler);
registered = 1;
}
}
void rvprof_init(const char* output_file){
if (g_rvprof.initialized) return;
@ -56,4 +69,7 @@ void rvprof_init(const char* output_file){
memset(&g_rvprof.regions, 0, sizeof(g_rvprof.regions));
memset(&g_rvprof.functions, 0, sizeof(g_rvprof.functions));
memset(&g_rvprof.stacks,0,sizeof(g_rvprof.stacks));
// register atexit handler to automate cleanup
register_atexit_handler();
}