diff options
Diffstat (limited to 'src/exit/at_quick_exit.c')
-rw-r--r-- | src/exit/at_quick_exit.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/exit/at_quick_exit.c b/src/exit/at_quick_exit.c new file mode 100644 index 00000000..85c3d26e --- /dev/null +++ b/src/exit/at_quick_exit.c @@ -0,0 +1,29 @@ +#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; +} |