OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utilsrc / srcX86MAC64 / Admin / gdb-7.7.1 / gdb / testsuite / gdb.cell / fork.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 2010-2014 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
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 General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18    Contributed by Ulrich Weigand <uweigand@de.ibm.com>  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <libspe2.h>
23 #include <pthread.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <unistd.h>
27
28 extern spe_program_handle_t fork_spu;
29
30 void *
31 spe_thread (void * arg)
32 {
33   int flags = 0;
34   unsigned int entry = SPE_DEFAULT_ENTRY;
35   spe_context_ptr_t *ctx = (spe_context_ptr_t *) arg;
36
37   spe_program_load (*ctx, &fork_spu);
38   spe_context_run (*ctx, &entry, flags, NULL, NULL, NULL);
39
40   pthread_exit (NULL);
41 }
42
43 int
44 main (void)
45 {
46   pthread_t pts;
47   spe_context_ptr_t ctx;
48   unsigned int value;
49   unsigned int pid;
50
51   ctx = spe_context_create (0, NULL);
52   pthread_create (&pts, NULL, &spe_thread, &ctx);
53
54   /* Wait until the SPU thread is running.  */
55   spe_out_intr_mbox_read (ctx, &value, 1, SPE_MBOX_ALL_BLOCKING);
56
57   pid = fork ();
58   if (pid == 0)
59     {
60       /* This is the child.  Just exit immediately.  */
61       exit (0);
62     }
63   else
64     {
65       /* This is the parent.  Wait for the child to exit.  */
66       waitpid (pid, NULL, 0);
67     }
68
69   /* Tell SPU to continue.  */
70   spe_in_mbox_write (ctx, &value, 1, SPE_MBOX_ALL_BLOCKING);
71   
72   pthread_join (pts, NULL);
73   spe_context_destroy (ctx);
74
75   return 0;
76 }
77