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

ruby-changes:47449

From: ko1 <ko1@a...>
Date: Thu, 10 Aug 2017 15:02:04 +0900 (JST)
Subject: [ruby-changes:47449] ko1:r59565 (trunk): introduce fiber_restore_thread.

ko1	2017-08-10 15:01:57 +0900 (Thu, 10 Aug 2017)

  New Revision: 59565

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59565

  Log:
    introduce fiber_restore_thread.
    
    * cont.c (fiber_restore_thread): added (separate from cont_restore_thread).
    
    * cont.c (fiber_setcontext): call fiber_restore_thread() directly.

  Modified files:
    trunk/cont.c
Index: cont.c
===================================================================
--- cont.c	(revision 59564)
+++ cont.c	(revision 59565)
@@ -578,13 +578,28 @@ cont_capture(volatile int *volatile stat https://github.com/ruby/ruby/blob/trunk/cont.c#L578
 }
 
 static inline void
+fiber_restore_thread(rb_thread_t *th, rb_fiber_t *fib)
+{
+    rb_thread_t *sth = &fib->cont.saved_thread;
+
+    th->ec = sth->ec;
+    sth->ec.vm_stack = NULL;
+    th->fiber = fib;
+
+    VM_ASSERT(th->ec.vm_stack != NULL);
+    VM_ASSERT(sth->status == THREAD_RUNNABLE);
+}
+
+
+static inline void
 cont_restore_thread(rb_context_t *cont)
 {
-    rb_thread_t *th = GET_THREAD(), *sth = &cont->saved_thread;
+    rb_thread_t *th = GET_THREAD();
 
     /* restore thread context */
     if (cont->type == CONTINUATION_CONTEXT) {
 	/* continuation */
+	rb_thread_t *sth = &cont->saved_thread;
 	const rb_fiber_t *fib;
 
 	th->fiber = sth->fiber;
@@ -613,16 +628,14 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L628
 	th->ec.ensure_list = sth->ec.ensure_list;
 	th->ec.errinfo = sth->ec.errinfo;
 	th->ec.trace_arg = sth->ec.trace_arg;
+
+	VM_ASSERT(th->ec.vm_stack != NULL);
+	VM_ASSERT(sth->status == THREAD_RUNNABLE);
     }
     else {
 	/* fiber */
-	th->ec = sth->ec;
-	sth->ec.vm_stack = NULL;
-	th->fiber = (rb_fiber_t*)cont;
+	fiber_restore_thread(th, (rb_fiber_t*)cont);
     }
-
-    VM_ASSERT(th->ec.vm_stack != NULL);
-    VM_ASSERT(sth->status == THREAD_RUNNABLE);
 }
 
 #if FIBER_USE_NATIVE
@@ -743,7 +756,7 @@ fiber_setcontext(rb_fiber_t *newfib, rb_ https://github.com/ruby/ruby/blob/trunk/cont.c#L756
     rb_thread_t *th = GET_THREAD(), *sth = &newfib->cont.saved_thread;
 
     /* restore thread context */
-    cont_restore_thread(&newfib->cont);
+    fiber_restore_thread(th, newfib);
     th->machine.stack_maxsize = sth->machine.stack_maxsize;
     if (sth->machine.stack_end && (newfib != oldfib)) {
 	rb_bug("fiber_setcontext: sth->machine.stack_end has non zero value");

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

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