projects
/
musl
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
move arch-invariant definitions out of bits/ioctl.h
[musl]
/
src
/
exit
/
at_quick_exit.c
1
#include <stdlib.h>
2
#include "libc.h"
3
#include "lock.h"
4
5
#define COUNT 32
6
7
static void (*funcs[COUNT])(void);
8
static int count;
9
static volatile int lock[1];
10
11
void __funcs_on_quick_exit()
12
{
13
void (*func)(void);
14
LOCK(lock);
15
while (count > 0) {
16
func = funcs[--count];
17
UNLOCK(lock);
18
func();
19
LOCK(lock);
20
}
21
}
22
23
int at_quick_exit(void (*func)(void))
24
{
25
int r = 0;
26
LOCK(lock);
27
if (count == 32) r = -1;
28
else funcs[count++] = func;
29
UNLOCK(lock);
30
return r;
31
}