split internal lock API out of libc.h, creating lock.h
[musl.git] / src / exit / at_quick_exit.c
blobd3ce6522df7dd810ee1014ae84a9ceaa08e66927
1 #include <stdlib.h>
2 #include "libc.h"
3 #include "lock.h"
5 #define COUNT 32
7 static void (*funcs[COUNT])(void);
8 static int count;
9 static volatile int lock[1];
11 void __funcs_on_quick_exit()
13 void (*func)(void);
14 LOCK(lock);
15 while (count > 0) {
16 func = funcs[--count];
17 UNLOCK(lock);
18 func();
19 LOCK(lock);
23 int at_quick_exit(void (*func)(void))
25 int r = 0;
26 LOCK(lock);
27 if (count == 32) r = -1;
28 else funcs[count++] = func;
29 UNLOCK(lock);
30 return r;