From b323b86b6b3a7283617b72b45521c554dba930c9 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 4 Feb 2010 07:17:03 +0000 Subject: * thread_pthread.c (native_thread_init_stack): use get_stack. patched by KOSAKI Motohiro [ruby-dev:40309] * thread_pthread.c (ruby_init_stack): use get_stack on platforms which have pthread_attr_get_np. (FreeBSD, DragonFlyBSD and NetBSD) This is because FreeBSD and DragonFly BSD must use pthread_attr_get_np to get stack size of main thread, but Mac OS X and Linux with LinuxThreads must use getrlimit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread_pthread.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'thread_pthread.c') diff --git a/thread_pthread.c b/thread_pthread.c index d2d8b04df1..8cfc637735 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -12,9 +12,6 @@ #ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION #include "gc.h" -#if defined(__FreeBSD__) || defined(__DragonFly) -#include -#endif #ifdef HAVE_SYS_RESOURCE_H #include @@ -234,10 +231,10 @@ get_stack(void **addr, size_t *size) CHECK_ERR(pthread_attr_getstacksize(&attr, size)); # endif CHECK_ERR(pthread_attr_getguardsize(&attr, &guard)); + *size -= guard; # ifndef HAVE_PTHREAD_GETATTR_NP pthread_attr_destroy(&attr); # endif - size -= guard; #elif defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP pthread_t th = pthread_self(); *addr = pthread_get_stackaddr_np(th); @@ -296,14 +293,11 @@ ruby_init_stack(volatile VALUE *addr } #endif { - size_t size = 0, space = 0; -#if defined(__FreeBSD__) || defined(__DragonFly) - pthread_attr_t attr; - if (pthread_attr_init(&attr) == 0) { - if (pthread_attr_get_np(native_main_thread.id, &attr) == 0) - pthread_attr_getstacksize(&attr, &size); - pthread_attr_destroy(&attr); - } + size_t size = 0; + size_t space = 0; +#if defined(HAVE_PTHREAD_ATTR_GET_NP) + void* addr; + get_stack(&addr, &size); #elif defined(HAVE_GETRLIMIT) struct rlimit rlim; if (getrlimit(RLIMIT_STACK, &rlim) == 0) { @@ -328,17 +322,14 @@ native_thread_init_stack(rb_thread_t *th) th->machine_stack_maxsize = native_main_thread.stack_maxsize; } else { -#ifdef HAVE_PTHREAD_GETATTR_NP - pthread_attr_t attr; +#ifdef STACKADDR_AVAILABLE void *start; - CHECK_ERR(pthread_getattr_np(curr, &attr)); -# if defined HAVE_PTHREAD_ATTR_GETSTACK - CHECK_ERR(pthread_attr_getstack(&attr, &start, &th->machine_stack_maxsize)); -# elif defined HAVE_PTHREAD_ATTR_GETSTACKSIZE && defined HAVE_PTHREAD_ATTR_GETSTACKADDR - CHECK_ERR(pthread_attr_getstackaddr(&attr, &start)); - CHECK_ERR(pthread_attr_getstacksize(&attr, &th->machine_stack_maxsize)); -# endif - th->machine_stack_start = start; + size_t size; + + if (get_stack(&start, &size) == 0) { + th->machine_stack_start = start; + th->machine_stack_maxsize = size; + } #else rb_raise(rb_eNotImpError, "ruby engine can initialize only in the main thread"); #endif -- cgit v1.2.3