1 /* Linuxthreads - a simple clone()-based implementation of Posix */
2 /* threads for Linux. */
3 /* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr) */
5 /* This program is free software; you can redistribute it and/or */
6 /* modify it under the terms of the GNU Library General Public License */
7 /* as published by the Free Software Foundation; either version 2 */
8 /* of the License, or (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU Library General Public License for more details. */
15 /* The "atfork" stuff */
22 #include "internals.h"
23 #include <bits/libc-lock.h>
26 extern int __libc_fork (void);
28 pid_t
__pthread_fork (struct fork_block
*b
)
33 __libc_lock_lock (b
->lock
);
35 /* Run all the registered preparation handlers. In reverse order. */
36 list_for_each_prev (runp
, &b
->prepare_list
)
38 struct fork_handler
*curp
;
39 curp
= list_entry (runp
, struct fork_handler
, list
);
43 __pthread_once_fork_prepare();
49 __pthread_reset_main_thread();
52 __pthread_once_fork_child();
54 /* Run the handlers registered for the child. */
55 list_for_each (runp
, &b
->child_list
)
57 struct fork_handler
*curp
;
58 curp
= list_entry (runp
, struct fork_handler
, list
);
62 __libc_lock_init (b
->lock
);
65 __pthread_once_fork_parent();
67 /* Run the handlers registered for the parent. */
68 list_for_each (runp
, &b
->parent_list
)
70 struct fork_handler
*curp
;
71 curp
= list_entry (runp
, struct fork_handler
, list
);
75 __libc_lock_unlock (b
->lock
);
84 return __libc_fork ();
86 weak_alias (__fork
, fork
);
90 return __libc_fork ();
92 weak_alias (__vfork
, vfork
);