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.
8 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
9 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
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.
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. */
37 #include "private/pthread_support.h"
39 #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
44 /* Invoked from GC_start_routine(). */
45 void * GC_CALLBACK GC_inner_start_routine(struct GC_stack_base *sb, void *arg)
47 void * (*start)(void *);
50 volatile GC_thread me =
51 GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
54 pthread_cleanup_push(GC_thread_exit_proc, me);
56 result = (*start)(start_arg);
58 GC_log_printf("Finishing thread 0x%x\n", (unsigned)pthread_self());
60 me -> status = result;
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. */
69 #endif /* GC_PTHREADS */