[前][次][番号順一覧][スレッド一覧]

ruby-changes:14716

From: naruse <ko1@a...>
Date: Thu, 4 Feb 2010 16:17:22 +0900 (JST)
Subject: [ruby-changes:14716] Ruby:r26572 (trunk): * thread_pthread.c (native_thread_init_stack): use get_stack.

naruse	2010-02-04 16:17:03 +0900 (Thu, 04 Feb 2010)

  New Revision: 26572

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26572

  Log:
    * 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.
      <http://www.nminoru.jp/~nminoru/programming/stackoverflow_handling.html>
      <http://d.hatena.ne.jp/nurse/20100204>

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c
    trunk/thread_pthread.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 26571)
+++ ChangeLog	(revision 26572)
@@ -1,8 +1,22 @@
+Thu Feb  4 15:47:27 2010  NARUSE, Yui  <naruse@r...>
+
+	* 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.
+	  <http://www.nminoru.jp/~nminoru/programming/stackoverflow_handling.html>
+	  <http://d.hatena.ne.jp/nurse/20100204>
+
 Thu Feb  4 09:55:38 2010  NARUSE, Yui  <naruse@r...>
 
-	* configure.in: FreeBSD, DragonFly BSD and Mac OS X needs
+	* configure.in: FreeBSD, DragonFly BSD and OpenBSD needs
 	  pthread_np.h to use pthread_*_np functions.
-	  Mac OS X's pthread_*_np also depend sys/signal.h,
+	  OpenBSD's pthread_*_np also depend sys/signal.h,
 	  but it is included at signal.h via vm_core.h via thread.c.
 
 Thu Feb  4 08:15:53 2010  Nobuyoshi Nakada  <nobu@r...>
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 26571)
+++ thread_pthread.c	(revision 26572)
@@ -12,9 +12,6 @@
 #ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
 
 #include "gc.h"
-#if defined(__FreeBSD__) || defined(__DragonFly)
-#include <pthread_np.h>
-#endif
 
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
@@ -234,10 +231,10 @@
     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 @@
     }
 #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 @@
 	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
Index: thread_pthread.h
===================================================================
--- thread_pthread.h	(revision 26571)
+++ thread_pthread.h	(revision 26572)
@@ -12,6 +12,9 @@
 #define RUBY_THREAD_PTHREAD_H
 
 #include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
 typedef pthread_t rb_thread_id_t;
 typedef pthread_mutex_t rb_thread_lock_t;
 typedef pthread_cond_t rb_thread_cond_t;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]