]> granicus.if.org Git - gc/blob - pthread_start.c
Update ChangeLog file (v7.2 - v7.4 changes only)
[gc] / 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 GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
46                                         struct GC_stack_base *sb, void *arg)
47 {
48   void * (*start)(void *);
49   void * start_arg;
50   void * result;
51   volatile GC_thread me =
52                 GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
53
54 # ifndef NACL
55     pthread_cleanup_push(GC_thread_exit_proc, me);
56 # endif
57   result = (*start)(start_arg);
58 # if defined(DEBUG_THREADS) && !defined(GC_PTHREAD_START_STANDALONE)
59     GC_log_printf("Finishing thread %p\n", (void *)pthread_self());
60 # endif
61   me -> status = result;
62   GC_end_stubborn_change(me); /* cannot use GC_dirty */
63 # ifndef NACL
64     pthread_cleanup_pop(1);
65     /* Cleanup acquires lock, ensuring that we can't exit while         */
66     /* a collection that thinks we're alive is trying to stop us.       */
67 # endif
68   return result;
69 }
70
71 #endif /* GC_PTHREADS */