repo.or.cz
/
musl.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
split internal lock API out of libc.h, creating lock.h
[musl.git]
/
src
/
exit
/
at_quick_exit.c
blob
d3ce6522df7dd810ee1014ae84a9ceaa08e66927
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
}