|
Packit |
d28291 |
/*
|
|
Packit |
d28291 |
* Copyright (c) 1994 by Xerox Corporation. All rights reserved.
|
|
Packit |
d28291 |
* Copyright (c) 1996 by Silicon Graphics. All rights reserved.
|
|
Packit |
d28291 |
* Copyright (c) 1998 by Fergus Henderson. All rights reserved.
|
|
Packit |
d28291 |
* Copyright (c) 2000-2010 by Hewlett-Packard Development Company.
|
|
Packit |
d28291 |
* All rights reserved.
|
|
Packit |
d28291 |
*
|
|
Packit |
d28291 |
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
|
Packit |
d28291 |
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|
Packit |
d28291 |
*
|
|
Packit |
d28291 |
* Permission is hereby granted to use or copy this program
|
|
Packit |
d28291 |
* for any purpose, provided the above notices are retained on all copies.
|
|
Packit |
d28291 |
* Permission to modify the code and to distribute modified code is granted,
|
|
Packit |
d28291 |
* provided the above notices are retained, and a notice that the code was
|
|
Packit |
d28291 |
* modified is included with the above copyright notice.
|
|
Packit |
d28291 |
*/
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
/* We want to make sure that GC_thread_exit_proc() is unconditionally */
|
|
Packit |
d28291 |
/* invoked, even if the client is not compiled with -fexceptions, but */
|
|
Packit |
d28291 |
/* the GC is. The workaround is to put GC_inner_start_routine() in its */
|
|
Packit |
d28291 |
/* own file (pthread_start.c), and undefine __EXCEPTIONS in the GCC */
|
|
Packit |
d28291 |
/* case at the top of the file. FIXME: it's still unclear whether this */
|
|
Packit |
d28291 |
/* will actually cause the exit handler to be invoked last when */
|
|
Packit |
d28291 |
/* thread_exit is called (and if -fexceptions is used). */
|
|
Packit Service |
0b1f68 |
#if 0 && defined(__GNUC__) && defined(__linux__)
|
|
Packit |
d28291 |
/* We undefine __EXCEPTIONS to avoid using GCC __cleanup__ attribute. */
|
|
Packit |
d28291 |
/* The current NPTL implementation of pthread_cleanup_push uses */
|
|
Packit |
d28291 |
/* __cleanup__ attribute when __EXCEPTIONS is defined (-fexceptions). */
|
|
Packit |
d28291 |
/* The stack unwinding and cleanup with __cleanup__ attributes work */
|
|
Packit |
d28291 |
/* correctly when everything is compiled with -fexceptions, but it is */
|
|
Packit |
d28291 |
/* not the requirement for this library clients to use -fexceptions */
|
|
Packit |
d28291 |
/* everywhere. With __EXCEPTIONS undefined, the cleanup routines are */
|
|
Packit |
d28291 |
/* registered with __pthread_register_cancel thus should work anyway. */
|
|
Packit |
d28291 |
# undef __EXCEPTIONS
|
|
Packit |
d28291 |
#endif
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
#include "private/pthread_support.h"
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
#if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
#include <pthread.h>
|
|
Packit |
d28291 |
#include <sched.h>
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
/* Invoked from GC_start_routine(). */
|
|
Packit |
d28291 |
GC_INNER_PTHRSTART void * GC_CALLBACK GC_inner_start_routine(
|
|
Packit |
d28291 |
struct GC_stack_base *sb, void *arg)
|
|
Packit |
d28291 |
{
|
|
Packit |
d28291 |
void * (*start)(void *);
|
|
Packit |
d28291 |
void * start_arg;
|
|
Packit |
d28291 |
void * result;
|
|
Packit |
d28291 |
volatile GC_thread me =
|
|
Packit |
d28291 |
GC_start_rtn_prepare_thread(&start, &start_arg, sb, arg);
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
# ifndef NACL
|
|
Packit |
d28291 |
pthread_cleanup_push(GC_thread_exit_proc, me);
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
result = (*start)(start_arg);
|
|
Packit |
d28291 |
# if defined(DEBUG_THREADS) && !defined(GC_PTHREAD_START_STANDALONE)
|
|
Packit |
d28291 |
GC_log_printf("Finishing thread %p\n", (void *)pthread_self());
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
me -> status = result;
|
|
Packit |
d28291 |
# ifndef NACL
|
|
Packit |
d28291 |
pthread_cleanup_pop(1);
|
|
Packit |
d28291 |
/* Cleanup acquires lock, ensuring that we can't exit while */
|
|
Packit |
d28291 |
/* a collection that thinks we're alive is trying to stop us. */
|
|
Packit |
d28291 |
# endif
|
|
Packit |
d28291 |
return result;
|
|
Packit |
d28291 |
}
|
|
Packit |
d28291 |
|
|
Packit |
d28291 |
#endif /* GC_PTHREADS */
|