4 static struct atfork_funcs
{
8 struct atfork_funcs
*prev
, *next
;
11 static volatile int lock
[2];
13 void __fork_handler(int who
)
15 struct atfork_funcs
*p
;
19 for (p
=funcs
; p
; p
= p
->next
) {
20 if (p
->prepare
) p
->prepare();
24 for (p
=funcs
; p
; p
= p
->prev
) {
25 if (!who
&& p
->parent
) p
->parent();
26 else if (who
&& p
->child
) p
->child();
33 int pthread_atfork(void (*prepare
)(void), void (*parent
)(void), void (*child
)(void))
35 struct atfork_funcs
*new = malloc(sizeof *new);
41 new->prepare
= prepare
;
44 if (funcs
) funcs
->prev
= new;