Line data Source code
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 499 : 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 499 : GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
53 :
54 : # ifndef NACL
55 499 : pthread_cleanup_push(GC_thread_exit_proc, me);
56 : # endif
57 499 : 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 151 : me -> status = result;
62 : # ifndef NACL
63 151 : pthread_cleanup_pop(1);
64 : /* Cleanup acquires lock, ensuring that we can't exit while */
65 : /* a collection that thinks we're alive is trying to stop us. */
66 : # endif
67 151 : return result;
68 : }
69 :
70 : #endif /* GC_PTHREADS */
|