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 pid_t __pthread_fork (struct fork_block *b)
31 __libc_lock_lock (b->lock);
33 /* Run all the registered preparation handlers. In reverse order. */
34 list_for_each_prev (runp, &b->prepare_list)
36 struct fork_handler *curp;
37 curp = list_entry (runp, struct fork_handler, list);
41 __pthread_once_fork_prepare();
47 __pthread_reset_main_thread();
50 __pthread_once_fork_child();
52 /* Run the handlers registered for the child. */
53 list_for_each (runp, &b->child_list)
55 struct fork_handler *curp;
56 curp = list_entry (runp, struct fork_handler, list);
60 __libc_lock_init (b->lock);
63 __pthread_once_fork_parent();
65 /* Run the handlers registered for the parent. */
66 list_for_each (runp, &b->parent_list)
68 struct fork_handler *curp;
69 curp = list_entry (runp, struct fork_handler, list);
73 __libc_lock_unlock (b->lock);
79 /* psm: have no idea why these are here, sjhill? */
83 return __libc_fork ();
85 weak_alias (__fork, fork)
89 return __libc_fork ();
91 weak_alias (__vfork, vfork)