lift child restrictions after multi-threaded fork
[musl.git] / src / exit / at_quick_exit.c
blobe4b5d78dbb70960d2906763daf9cb19751f68ddb
1 #include <stdlib.h>
2 #include "libc.h"
3 #include "lock.h"
4 #include "fork_impl.h"
6 #define COUNT 32
8 static void (*funcs[COUNT])(void);
9 static int count;
10 static volatile int lock[1];
11 volatile int *const __at_quick_exit_lockptr = lock;
13 void __funcs_on_quick_exit()
15 void (*func)(void);
16 LOCK(lock);
17 while (count > 0) {
18 func = funcs[--count];
19 UNLOCK(lock);
20 func();
21 LOCK(lock);
25 int at_quick_exit(void (*func)(void))
27 int r = 0;
28 LOCK(lock);
29 if (count == 32) r = -1;
30 else funcs[count++] = func;
31 UNLOCK(lock);
32 return r;