summaryrefslogtreecommitdiff
path: root/fork.c
blob: 0b275584f092895f53b0de150ae814700b4177ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * fork.c
 *
 * Description:
 * Implementation of fork() for POSIX threads.
 */

int
pthread_atfork(void (*prepare)(void),
	       void (*parent)(void),
	       void (*child)(void))
{
  /* Push handlers (unless NULL) onto their respective stacks. */

  if (prepare != NULL)
    {
      /* Push prepare. */
      /* If push fails, return ENOMEM. */
    }

  if (parent != NULL)
    {
      /* Push parent. */
      /* If push fails, return ENOMEM. */
    }

  if (child != NULL)
    {
      /* Push child. */
      /* If push fails, return ENOMEM. */
    }

  /* Everything is okay. */
  return 0;
}

/* It looks like the GNU linker is capable of selecting this version of
   fork() over a version provided in more primitive libraries further down
   the linker command line. */

pid_t
fork()
{
  pid_t pid;

  /* Pop prepare handlers here. */

  /* Now call Cygwin32's fork(). */

  if ((pid = _fork()) > 0)
    {
      /* Pop parent handlers. */
      return pid;
    }
  else
    {
      /* Pop child handlers. */
      /* Terminate all threads except pthread_self() using
	 pthread_cancel(). */
      return 0;
    }

  /* Not reached. */
}