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

ruby-changes:47660

From: ko1 <ko1@a...>
Date: Fri, 8 Sep 2017 15:21:35 +0900 (JST)
Subject: [ruby-changes:47660] ko1:r59776 (trunk): move th->fiber to ec->fiber.

ko1	2017-09-08 15:21:30 +0900 (Fri, 08 Sep 2017)

  New Revision: 59776

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

  Log:
    move th->fiber to ec->fiber.
    
    * vm_core.h (rb_thread_t::fiber): move fiber field to
      rb_execution_context_t::fiber.

  Modified files:
    trunk/cont.c
    trunk/vm.c
    trunk/vm_core.h
Index: cont.c
===================================================================
--- cont.c	(revision 59775)
+++ cont.c	(revision 59776)
@@ -248,7 +248,7 @@ cont_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L248
 	    const rb_thread_t *th = rb_thread_ptr(cont->saved_thread.self);
 	    const rb_fiber_t *fib = (rb_fiber_t*)cont;
 
-	    if ((th->fiber != fib) && FIBER_SUSPENDED_P(fib)) {
+	    if ((th->ec.fiber != fib) && FIBER_SUSPENDED_P(fib)) {
 		rb_gc_mark_locations(cont->machine.stack,
 				     cont->machine.stack + cont->machine.stack_size);
 	    }
@@ -282,14 +282,14 @@ cont_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/cont.c#L282
 	const rb_fiber_t *fib = (rb_fiber_t*)cont;
 	const rb_thread_t *const th = GET_THREAD();
 #ifdef _WIN32
-	if (th && th->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) {
+	if (th && th->ec.fiber != fib && cont->type != ROOT_FIBER_CONTEXT) {
 	    /* don't delete root fiber handle */
 	    if (fib->fib_handle) {
 		DeleteFiber(fib->fib_handle);
 	    }
 	}
 #else /* not WIN32 */
-	if (th && th->fiber != fib) {
+	if (th && th->ec.fiber != fib) {
 	    if (fib->ss_sp) {
 		if (cont->type == ROOT_FIBER_CONTEXT) {
 		    rb_bug("Illegal root fiber parameter");
@@ -502,7 +502,7 @@ cont_init(rb_context_t *cont, rb_thread_ https://github.com/ruby/ruby/blob/trunk/cont.c#L502
     cont_save_thread(cont, th);
     cont->saved_thread.self = th->self;
     cont->saved_thread.machine.stack_maxsize = th->machine.stack_maxsize;
-    cont->saved_thread.fiber = th->fiber;
+
     cont->saved_thread.ec.local_storage = NULL;
     cont->saved_thread.ec.local_storage_recursive_hash = Qnil;
     cont->saved_thread.ec.local_storage_recursive_hash_for_trace = Qnil;
@@ -589,7 +589,6 @@ fiber_restore_thread(rb_thread_t *th, rb https://github.com/ruby/ruby/blob/trunk/cont.c#L589
 
     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);
@@ -607,8 +606,8 @@ cont_restore_thread(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L606
 	rb_thread_t *sth = &cont->saved_thread;
 	const rb_fiber_t *fib;
 
-	th->fiber = sth->fiber;
-	fib = th->fiber ? th->fiber : th->root_fiber;
+	fib = th->ec.fiber = sth->ec.fiber;
+	if (fib == NULL) fib = th->root_fiber;
 
 	if (fib && fib->cont.saved_thread.ec.vm_stack) {
 	    th->ec.vm_stack_size = fib->cont.saved_thread.ec.vm_stack_size;
@@ -1134,8 +1133,8 @@ rb_cont_call(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/cont.c#L1133
     if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) {
 	rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier");
     }
-    if (cont->saved_thread.fiber) {
-	if (th->fiber != cont->saved_thread.fiber) {
+    if (cont->saved_thread.ec.fiber) {
+	if (th->ec.fiber != cont->saved_thread.ec.fiber) {
 	    rb_raise(rb_eRuntimeError, "continuation called across fiber");
 	}
     }
@@ -1242,6 +1241,7 @@ fiber_t_alloc(VALUE fibval) https://github.com/ruby/ruby/blob/trunk/cont.c#L1241
     fib->cont.self = fibval;
     fib->cont.type = FIBER_CONTEXT;
     cont_init(&fib->cont, th);
+    fib->cont.saved_thread.ec.fiber = fib;
     fib->prev = NULL;
 
     /* fib->status == 0 == CREATED
@@ -1327,7 +1327,7 @@ void https://github.com/ruby/ruby/blob/trunk/cont.c#L1327
 rb_fiber_start(void)
 {
     rb_thread_t *th = GET_THREAD();
-    rb_fiber_t *fib = th->fiber;
+    rb_fiber_t *fib = th->ec.fiber;
     rb_proc_t *proc;
     enum ruby_tag_type state;
 
@@ -1381,7 +1381,7 @@ root_fiber_alloc(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/cont.c#L1381
 #endif
 #endif
     fiber_status_set(fib, FIBER_RESUMED); /* skip CREATED */
-    th->root_fiber = th->fiber = fib;
+    th->root_fiber = th->ec.fiber = fib;
     return fib;
 }
 
@@ -1389,12 +1389,12 @@ static inline rb_fiber_t* https://github.com/ruby/ruby/blob/trunk/cont.c#L1389
 fiber_current(void)
 {
     rb_thread_t *th = GET_THREAD();
-    if (th->fiber == 0) {
+    if (th->ec.fiber == NULL) {
 	rb_fiber_t *fib = root_fiber_alloc(th);
 	/* Running thread object has stack management responsibility */
 	fib->cont.saved_thread.ec.vm_stack = NULL;
     }
-    return th->fiber;
+    return th->ec.fiber;
 }
 
 static inline rb_fiber_t*
@@ -1428,8 +1428,8 @@ fiber_store(rb_fiber_t *next_fib, rb_thr https://github.com/ruby/ruby/blob/trunk/cont.c#L1428
 {
     rb_fiber_t *fib;
 
-    if (th->fiber) {
-	fib = th->fiber;
+    if (th->ec.fiber != NULL) {
+	fib = th->ec.fiber;
 	cont_save_thread(&fib->cont, th);
     }
     else {
@@ -1471,7 +1471,7 @@ fiber_store(rb_fiber_t *next_fib, rb_thr https://github.com/ruby/ruby/blob/trunk/cont.c#L1471
 	terminated_machine_stack.size = 0;
     }
 #endif /* not _WIN32 */
-    fib = th->fiber;
+    fib = th->ec.fiber;
     if (fib->cont.argc == -1) rb_exc_raise(fib->cont.value);
     return fib->cont.value;
 
@@ -1502,7 +1502,7 @@ fiber_switch(rb_fiber_t *fib, int argc, https://github.com/ruby/ruby/blob/trunk/cont.c#L1502
     rb_context_t *cont = &fib->cont;
     rb_thread_t *th = GET_THREAD();
 
-    if (th->fiber == fib) {
+    if (th->ec.fiber == fib) {
 	/* ignore fiber context switch
          * because destination fiber is same as current fiber
 	 */
@@ -1518,7 +1518,7 @@ fiber_switch(rb_fiber_t *fib, int argc, https://github.com/ruby/ruby/blob/trunk/cont.c#L1518
     else if (FIBER_TERMINATED_P(fib)) {
 	value = rb_exc_new2(rb_eFiberError, "dead fiber called");
 
-	if (!FIBER_TERMINATED_P(th->fiber)) {
+	if (!FIBER_TERMINATED_P(th->ec.fiber)) {
 	    rb_exc_raise(value);
 	    VM_UNREACHABLE(fiber_switch);
 	}
@@ -1532,7 +1532,7 @@ fiber_switch(rb_fiber_t *fib, int argc, https://github.com/ruby/ruby/blob/trunk/cont.c#L1532
 	    cont->argc = -1;
 	    cont->value = value;
 #if FIBER_USE_NATIVE
-	    fiber_setcontext(th->root_fiber, th->fiber);
+	    fiber_setcontext(th->root_fiber, th->ec.fiber);
 #else
 	    cont_restore_0(cont, &value);
 #endif
@@ -1610,7 +1610,7 @@ rb_fiber_reset_root_local_storage(VALUE https://github.com/ruby/ruby/blob/trunk/cont.c#L1610
 {
     rb_thread_t *th = rb_thread_ptr(thval);
 
-    if (th->root_fiber && th->root_fiber != th->fiber) {
+    if (th->root_fiber && th->root_fiber != th->ec.fiber) {
 	th->ec.local_storage = th->root_fiber->cont.saved_thread.ec.local_storage;
     }
 }
Index: vm.c
===================================================================
--- vm.c	(revision 59775)
+++ vm.c	(revision 59776)
@@ -2395,6 +2395,7 @@ rb_execution_context_mark(const rb_execu https://github.com/ruby/ruby/blob/trunk/vm.c#L2395
     rb_mark_tbl(ec->local_storage);
     RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash);
     RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash_for_trace);
+    rb_fiber_mark_self(ec->fiber);
 }
 
 void
@@ -2423,7 +2424,6 @@ rb_thread_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L2424
     RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack);
     RUBY_MARK_UNLESS_NULL(th->top_self);
     RUBY_MARK_UNLESS_NULL(th->top_wrapper);
-    rb_fiber_mark_self(th->fiber);
     rb_fiber_mark_self(th->root_fiber);
     RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
     RUBY_MARK_UNLESS_NULL(th->last_status);
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 59775)
+++ vm_core.h	(revision 59776)
@@ -765,6 +765,8 @@ typedef struct rb_execution_context_stru https://github.com/ruby/ruby/blob/trunk/vm_core.h#L765
 
     /* ensure & callcc */
     rb_ensure_list_t *ensure_list;
+
+    rb_fiber_t *fiber;
 } rb_execution_context_t;
 
 typedef struct rb_thread_struct {
@@ -847,7 +849,6 @@ typedef struct rb_thread_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L849
     rb_hook_list_t event_hooks;
 
     /* fiber */
-    rb_fiber_t *fiber;
     rb_fiber_t *root_fiber;
     rb_jmpbuf_t root_jmpbuf;
 

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

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