OSDN Git Service

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