source:
azure_iot_hub_mbedtls/trunk/musl-1.1.18/src/exit/at_quick_exit.c@
398
Last change on this file since 398 was 398, checked in by , 5 years ago | |
---|---|
|
|
File size: 431 bytes |
Rev | Line | |
---|---|---|
[398] | 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 | if (count == 32) return -1; | |
25 | LOCK(lock); | |
26 | funcs[count++] = func; | |
27 | UNLOCK(lock); | |
28 | return 0; | |
29 | } |
Note:
See TracBrowser
for help on using the repository browser.