mirror of
https://github.com/fluencelabs/musl
synced 2025-05-29 07:31:53 +00:00
30 lines
422 B
C
30 lines
422 B
C
#include <stdlib.h>
|
|
#include "libc.h"
|
|
|
|
#define COUNT 32
|
|
|
|
static void (*funcs[COUNT])(void);
|
|
static int count;
|
|
static int lock[2];
|
|
|
|
void __funcs_on_quick_exit()
|
|
{
|
|
void (*func)(void);
|
|
LOCK(lock);
|
|
while (count > 0) {
|
|
func = funcs[--count];
|
|
UNLOCK(lock);
|
|
func();
|
|
LOCK(lock);
|
|
}
|
|
}
|
|
|
|
int at_quick_exit(void (*func)(void))
|
|
{
|
|
if (count == 32) return -1;
|
|
LOCK(lock);
|
|
funcs[count++] = func;
|
|
UNLOCK(lock);
|
|
return 0;
|
|
}
|