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

ruby-changes:31627

From: nobu <ko1@a...>
Date: Mon, 18 Nov 2013 22:47:17 +0900 (JST)
Subject: [ruby-changes:31627] nobu:r43706 (trunk): thread_pthread.c: use get_main_stack properly

nobu	2013-11-18 22:47:12 +0900 (Mon, 18 Nov 2013)

  New Revision: 43706

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

  Log:
    thread_pthread.c: use get_main_stack properly
    
    * thread_pthread.c (ruby_init_stack): set stack_start properly by
      get_main_stack() if possible.

  Modified files:
    trunk/ChangeLog
    trunk/thread_pthread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43705)
+++ ChangeLog	(revision 43706)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Nov 18 22:47:11 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread_pthread.c (ruby_init_stack): set stack_start properly by
+	  get_main_stack() if possible.
+
 Mon Nov 18 22:45:49 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* eval_jump.c (rb_exec_end_proc): unlink and free procs data before
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 43705)
+++ thread_pthread.c	(revision 43706)
@@ -485,7 +485,7 @@ static rb_thread_t *register_cached_thre https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L485
 #elif defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP
 #define STACKADDR_AVAILABLE 1
 #undef MAINSTACKADDR_AVAILABLE
-#define MAINSTACKADDR_AVAILABLE 0
+#define MAINSTACKADDR_AVAILABLE 1
 void *pthread_get_stackaddr_np(pthread_t);
 size_t pthread_get_stacksize_np(pthread_t);
 #elif defined HAVE_THR_STKSEGMENT || defined HAVE_PTHREAD_STACKSEG_NP
@@ -677,7 +677,20 @@ ruby_init_stack(volatile VALUE *addr https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L677
         native_main_thread.register_stack_start = (VALUE*)bsp;
     }
 #endif
+#if MAINSTACKADDR_AVAILABLE
+    if (native_main_thread.stack_maxsize) return;
+    {
+	void* stackaddr;
+	size_t size;
+	if (get_main_stack(&stackaddr, &size) == 0) {
+	    native_main_thread.stack_maxsize = size;
+	    native_main_thread.stack_start = stackaddr;
+	    return;
+	}
+    }
+#endif
     {
+#if defined(HAVE_GETRLIMIT)
 #if defined(PTHREAD_STACK_DEFAULT)
 # if PTHREAD_STACK_DEFAULT < RUBY_STACK_SPACE*5
 #  error "PTHREAD_STACK_DEFAULT is too small"
@@ -686,15 +699,7 @@ ruby_init_stack(volatile VALUE *addr https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L699
 #else
 	size_t size = RUBY_VM_THREAD_VM_STACK_SIZE;
 #endif
-	size_t space = space_size(size);
-#if MAINSTACKADDR_AVAILABLE
-	void* stackaddr;
-	STACK_GROW_DIR_DETECTION;
-	if (get_main_stack(&stackaddr, &size) == 0) {
-            space = STACK_DIR_UPPER((char *)addr - (char *)stackaddr, (char *)stackaddr - (char *)addr);
-        }
-	native_main_thread.stack_maxsize = size - space;
-#elif defined(HAVE_GETRLIMIT)
+	size_t space;
 	int pagesize = getpagesize();
 	struct rlimit rlim;
         STACK_GROW_DIR_DETECTION;

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

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