implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / pthread_start.c
1 /*
2  * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
3  * Copyright (c) 1996 by Silicon Graphics.  All rights reserved.
4  * Copyright (c) 1998 by Fergus Henderson.  All rights reserved.
5  * Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
6  * All rights reserved.
7  *
8  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
10  *
11  * Permission is hereby granted to use or copy this program
12  * for any purpose,  provided the above notices are retained on all copies.
13  * Permission to modify the code and to distribute modified code is granted,
14  * provided the above notices are retained, and a notice that the code was
15  * modified is included with the above copyright notice.
16  */
17
18 /* We want to make sure that GC_thread_exit_proc() is unconditionally   */
19 /* invoked, even if the client is not compiled with -fexceptions, but   */
20 /* the GC is.  The workaround is to put GC_inner_start_routine() in its */
21 /* own file (pthread_start.c), and undefine __EXCEPTIONS in the GCC     */
22 /* case at the top of the file.  FIXME: it's still unclear whether this */
23 /* will actually cause the exit handler to be invoked last when         */
24 /* thread_exit is called (and if -fexceptions is used).                 */
25 #if defined(__GNUC__) && defined(__linux__)
26   /* We undefine __EXCEPTIONS to avoid using GCC __cleanup__ attribute. */
27   /* The current NPTL implementation of pthread_cleanup_push uses       */
28   /* __cleanup__ attribute when __EXCEPTIONS is defined (-fexceptions). */
29   /* The stack unwinding and cleanup with __cleanup__ attributes work   */
30   /* correctly when everything is compiled with -fexceptions, but it is */
31   /* not the requirement for this library clients to use -fexceptions   */
32   /* everywhere.  With __EXCEPTIONS undefined, the cleanup routines are */
33   /* registered with __pthread_register_cancel thus should work anyway. */
34 # undef __EXCEPTIONS
35 #endif
36
37 #include "private/pthread_support.h"
38
39 #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
40
41 #include <pthread.h>
42 #include <sched.h>
43
44 /* Invoked from GC_start_routine(). */
45 void * GC_CALLBACK GC_inner_start_routine(struct GC_stack_base *sb, void *arg)
46 {
47   void * (*start)(void *);
48   void * start_arg;
49   void * result;
50   volatile GC_thread me =
51                 GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
52
53 # ifndef NACL
54     pthread_cleanup_push(GC_thread_exit_proc, me);
55 # endif
56   result = (*start)(start_arg);
57 # ifdef DEBUG_THREADS
58     GC_log_printf("Finishing thread 0x%x\n", (unsigned)pthread_self());
59 # endif
60   me -> status = result;
61 # ifndef NACL
62     pthread_cleanup_pop(1);
63     /* Cleanup acquires lock, ensuring that we can't exit while         */
64     /* a collection that thinks we're alive is trying to stop us.       */
65 # endif
66   return result;
67 }
68
69 #endif /* GC_PTHREADS */