From: John David Anglin Date: Sun, 27 Feb 2011 00:24:18 +0000 (+0000) Subject: backport: re PR boehm-gc/34544 (pthread_default_stacksize_np failed.) X-Git-Tag: releases/gcc-4.3.6~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4c79b2365ff15c380a4f035cbd5ff94154dad0f3;p=thirdparty%2Fgcc.git backport: re PR boehm-gc/34544 (pthread_default_stacksize_np failed.) Backport from mainline: 2010-08-22 John David Anglin PR boehm-gc/34544 * gthr-posix.h (__gthread_active_init): Delete. (__gthread_active_p): Do activity check here. Don't include errno.h on hppa-hpux. Update comment. * gthr-posix95.h (__gthread_active_init): Delete. (__gthread_active_p): Do activity check here. Don't include errno.h on hppa-hpux. Update comment. From-SVN: r170527 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3c9408316579..69796fcb2a4f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2011-02-26 John David Anglin + + Backport from mainline: + 2010-08-22 John David Anglin + + PR boehm-gc/34544 + * gthr-posix.h (__gthread_active_init): Delete. + (__gthread_active_p): Do activity check here. + Don't include errno.h on hppa-hpux. Update comment. + * gthr-posix95.h (__gthread_active_init): Delete. + (__gthread_active_p): Do activity check here. + Don't include errno.h on hppa-hpux. Update comment. + 2011-02-24 John David Anglin * config.gcc (hppa[12]*-*-hpux11*): Set extra_parts. diff --git a/gcc/gthr-posix.h b/gcc/gthr-posix.h index a90dc11e6394..51b3ea8d6807 100644 --- a/gcc/gthr-posix.h +++ b/gcc/gthr-posix.h @@ -224,61 +224,34 @@ __gthread_active_p (void) calls in shared flavors of the HP-UX C library. Most of the stubs have no functionality. The details are described in the "libc cumulative patch" for each subversion of HP-UX 11. There are two special interfaces - provided for checking whether an application is linked to a pthread + provided for checking whether an application is linked to a shared pthread library or not. However, these interfaces aren't available in early - libc versions. We also can't use pthread_once as some libc versions - call the init function. So, we use pthread_create to check whether it - is possible to create a thread or not. The stub implementation returns - the error number ENOSYS. */ + libpthread libraries. We also need a test that works for archive + libraries. We can't use pthread_once as some libc versions call the + init function. We also can't use pthread_create or pthread_attr_init + as these create a thread and thereby prevent changing the default stack + size. The function pthread_default_stacksize_np is available in both + the archive and shared versions of libpthread. It can be used to + determine the default pthread stack size. There is a stub in some + shared libc versions which returns a zero size if pthreads are not + active. We provide an equivalent stub to handle cases where libc + doesn't provide one. */ #if defined(__hppa__) && defined(__hpux__) -#include - static volatile int __gthread_active = -1; -static void * -__gthread_start (void *arg __attribute__((unused))) -{ - return NULL; -} - -static void __gthread_active_init (void) __attribute__((noinline)); -static void -__gthread_active_init (void) -{ - static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_t t; - pthread_attr_t a; - int result; - - __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex); - if (__gthread_active < 0) - { - __gthrw_(pthread_attr_init) (&a); - __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED); - result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL); - if (result != ENOSYS) - __gthread_active = 1; - else - __gthread_active = 0; - __gthrw_(pthread_attr_destroy) (&a); - } - __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex); -} - static inline int __gthread_active_p (void) { /* Avoid reading __gthread_active twice on the main code path. */ int __gthread_active_latest_value = __gthread_active; + size_t __s; - /* This test is not protected to avoid taking a lock on the main code - path so every update of __gthread_active in a threaded program must - be atomic with regard to the result of the test. */ if (__builtin_expect (__gthread_active_latest_value < 0, 0)) { - __gthread_active_init (); + pthread_default_stacksize_np (0, &__s); + __gthread_active = __s ? 1 : 0; __gthread_active_latest_value = __gthread_active; } diff --git a/gcc/gthr-posix95.h b/gcc/gthr-posix95.h index 9d6939eaf916..66a00af9e323 100644 --- a/gcc/gthr-posix95.h +++ b/gcc/gthr-posix95.h @@ -187,61 +187,34 @@ __gthread_active_p (void) calls in shared flavors of the HP-UX C library. Most of the stubs have no functionality. The details are described in the "libc cumulative patch" for each subversion of HP-UX 11. There are two special interfaces - provided for checking whether an application is linked to a pthread + provided for checking whether an application is linked to a shared pthread library or not. However, these interfaces aren't available in early - libc versions. We also can't use pthread_once as some libc versions - call the init function. So, we use pthread_create to check whether it - is possible to create a thread or not. The stub implementation returns - the error number ENOSYS. */ + pthread libraries. We also need a test that works for archive + libraries. We can't use pthread_once as some libc versions call the + init function. We also can't use pthread_create or pthread_attr_init + as these create a thread and thereby prevent changing the default stack + size. The function pthread_default_stacksize_np is available in both + the archive and shared versions of libpthread. It can be used to + determine the default pthread stack size. There is a stub in some + shared libc versions which returns a zero size if pthreads are not + active. We provide an equivalent stub to handle cases where libc + doesn't provide one. */ #if defined(__hppa__) && defined(__hpux__) -#include - static volatile int __gthread_active = -1; -static void * -__gthread_start (void *arg __attribute__((unused))) -{ - return NULL; -} - -static void __gthread_active_init (void) __attribute__((noinline)); -static void -__gthread_active_init (void) -{ - static pthread_mutex_t __gthread_active_mutex = PTHREAD_MUTEX_INITIALIZER; - pthread_t t; - pthread_attr_t a; - int result; - - __gthrw_(pthread_mutex_lock) (&__gthread_active_mutex); - if (__gthread_active < 0) - { - __gthrw_(pthread_attr_init) (&a); - __gthrw_(pthread_attr_setdetachstate) (&a, PTHREAD_CREATE_DETACHED); - result = __gthrw_(pthread_create) (&t, &a, __gthread_start, NULL); - if (result != ENOSYS) - __gthread_active = 1; - else - __gthread_active = 0; - __gthrw_(pthread_attr_destroy) (&a); - } - __gthrw_(pthread_mutex_unlock) (&__gthread_active_mutex); -} - static inline int __gthread_active_p (void) { /* Avoid reading __gthread_active twice on the main code path. */ int __gthread_active_latest_value = __gthread_active; + size_t __s; - /* This test is not protected to avoid taking a lock on the main code - path so every update of __gthread_active in a threaded program must - be atomic with regard to the result of the test. */ if (__builtin_expect (__gthread_active_latest_value < 0, 0)) { - __gthread_active_init (); + pthread_default_stacksize_np (0, &__s); + __gthread_active = __s ? 1 : 0; __gthread_active_latest_value = __gthread_active; }