1
0

at_quick_exit.c 431 B

1234567891011121314151617181920212223242526272829
  1. #include <stdlib.h>
  2. #include "libc.h"
  3. #define COUNT 32
  4. static void (*funcs[COUNT])(void);
  5. static int count;
  6. static volatile int lock[2];
  7. void __funcs_on_quick_exit()
  8. {
  9. void (*func)(void);
  10. LOCK(lock);
  11. while (count > 0) {
  12. func = funcs[--count];
  13. UNLOCK(lock);
  14. func();
  15. LOCK(lock);
  16. }
  17. }
  18. int at_quick_exit(void (*func)(void))
  19. {
  20. if (count == 32) return -1;
  21. LOCK(lock);
  22. funcs[count++] = func;
  23. UNLOCK(lock);
  24. return 0;
  25. }