]> git.proxmox.com Git - wasi-libc.git/blame - libc-top-half/musl/src/exit/at_quick_exit.c
Update to musl 1.2.2.
[wasi-libc.git] / libc-top-half / musl / src / exit / at_quick_exit.c
CommitLineData
320054e8
DG
1#include <stdlib.h>
2#include "libc.h"
3#include "lock.h"
322bd4ff 4#include "fork_impl.h"
320054e8
DG
5
6#define COUNT 32
7
8static void (*funcs[COUNT])(void);
9static int count;
322bd4ff 10#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
320054e8 11static volatile int lock[1];
322bd4ff
DG
12volatile int *const __at_quick_exit_lockptr = lock;
13#endif
320054e8
DG
14
15void __funcs_on_quick_exit()
16{
17 void (*func)(void);
18 LOCK(lock);
19 while (count > 0) {
20 func = funcs[--count];
21 UNLOCK(lock);
22 func();
23 LOCK(lock);
24 }
25}
26
27int at_quick_exit(void (*func)(void))
28{
29 int r = 0;
30 LOCK(lock);
31 if (count == 32) r = -1;
32 else funcs[count++] = func;
33 UNLOCK(lock);
34 return r;
35}