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