Back to index

glibc  2.9
Functions
ptfork.c File Reference
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include "pthread.h"
#include "internals.h"
#include <bits/libc-lock.h>
#include "fork.h"

Go to the source code of this file.

Functions

int __libc_fork (void)
pid_t __pthread_fork (struct fork_block *b)

Function Documentation

int __libc_fork ( void  )

Definition at line 37 of file fork.c.

{
  return __libc_maybe_call2 (pthread_fork, (&__fork_block), ARCH_FORK ());
}

Here is the call graph for this function:

pid_t __pthread_fork ( struct fork_block b)

Definition at line 28 of file ptfork.c.

{
  pid_t pid;
  list_t *runp;

  __libc_lock_lock (b->lock);

  /* Run all the registered preparation handlers.  In reverse order.  */
  list_for_each_prev (runp, &b->prepare_list)
    {
      struct fork_handler *curp;
      curp = list_entry (runp, struct fork_handler, list);
      curp->handler ();
    }

  __pthread_once_fork_prepare();
  __flockfilelist();

  pid = ARCH_FORK ();

  if (pid == 0) {
    __pthread_reset_main_thread();

    __fresetlockfiles();
    __pthread_once_fork_child();

    /* Run the handlers registered for the child.  */
    list_for_each (runp, &b->child_list)
      {
       struct fork_handler *curp;
       curp = list_entry (runp, struct fork_handler, list);
       curp->handler ();
      }

    __libc_lock_init (b->lock);
  } else {
    __funlockfilelist();
    __pthread_once_fork_parent();

    /* Run the handlers registered for the parent.  */
    list_for_each (runp, &b->parent_list)
      {
       struct fork_handler *curp;
       curp = list_entry (runp, struct fork_handler, list);
       curp->handler ();
      }

    __libc_lock_unlock (b->lock);
  }

  return pid;
}

Here is the call graph for this function: