* vm_core.h (rb_thread_t::fiber): move fiber field to
  rb_execution_context_t::fiber.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-09-08 06:21:30 +00:00
Родитель eb99ed161b
Коммит 8e03791373
3 изменённых файлов: 23 добавлений и 22 удалений

40
cont.c
Просмотреть файл

@ -248,7 +248,7 @@ cont_mark(void *ptr)
const rb_thread_t *th = rb_thread_ptr(cont->saved_thread.self); const rb_thread_t *th = rb_thread_ptr(cont->saved_thread.self);
const rb_fiber_t *fib = (rb_fiber_t*)cont; 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, rb_gc_mark_locations(cont->machine.stack,
cont->machine.stack + cont->machine.stack_size); cont->machine.stack + cont->machine.stack_size);
} }
@ -282,14 +282,14 @@ cont_free(void *ptr)
const rb_fiber_t *fib = (rb_fiber_t*)cont; const rb_fiber_t *fib = (rb_fiber_t*)cont;
const rb_thread_t *const th = GET_THREAD(); const rb_thread_t *const th = GET_THREAD();
#ifdef _WIN32 #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 */ /* don't delete root fiber handle */
if (fib->fib_handle) { if (fib->fib_handle) {
DeleteFiber(fib->fib_handle); DeleteFiber(fib->fib_handle);
} }
} }
#else /* not WIN32 */ #else /* not WIN32 */
if (th && th->fiber != fib) { if (th && th->ec.fiber != fib) {
if (fib->ss_sp) { if (fib->ss_sp) {
if (cont->type == ROOT_FIBER_CONTEXT) { if (cont->type == ROOT_FIBER_CONTEXT) {
rb_bug("Illegal root fiber parameter"); rb_bug("Illegal root fiber parameter");
@ -502,7 +502,7 @@ cont_init(rb_context_t *cont, rb_thread_t *th)
cont_save_thread(cont, th); cont_save_thread(cont, th);
cont->saved_thread.self = th->self; cont->saved_thread.self = th->self;
cont->saved_thread.machine.stack_maxsize = th->machine.stack_maxsize; 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 = NULL;
cont->saved_thread.ec.local_storage_recursive_hash = Qnil; cont->saved_thread.ec.local_storage_recursive_hash = Qnil;
cont->saved_thread.ec.local_storage_recursive_hash_for_trace = Qnil; cont->saved_thread.ec.local_storage_recursive_hash_for_trace = Qnil;
@ -589,7 +589,6 @@ fiber_restore_thread(rb_thread_t *th, rb_fiber_t *fib)
th->ec = sth->ec; th->ec = sth->ec;
sth->ec.vm_stack = NULL; sth->ec.vm_stack = NULL;
th->fiber = fib;
VM_ASSERT(th->ec.vm_stack != NULL); VM_ASSERT(th->ec.vm_stack != NULL);
VM_ASSERT(sth->status == THREAD_RUNNABLE); VM_ASSERT(sth->status == THREAD_RUNNABLE);
@ -607,8 +606,8 @@ cont_restore_thread(rb_context_t *cont)
rb_thread_t *sth = &cont->saved_thread; rb_thread_t *sth = &cont->saved_thread;
const rb_fiber_t *fib; const rb_fiber_t *fib;
th->fiber = sth->fiber; fib = th->ec.fiber = sth->ec.fiber;
fib = th->fiber ? th->fiber : th->root_fiber; if (fib == NULL) fib = th->root_fiber;
if (fib && fib->cont.saved_thread.ec.vm_stack) { if (fib && fib->cont.saved_thread.ec.vm_stack) {
th->ec.vm_stack_size = fib->cont.saved_thread.ec.vm_stack_size; th->ec.vm_stack_size = fib->cont.saved_thread.ec.vm_stack_size;
@ -1134,8 +1133,8 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) { if (cont->saved_thread.ec.protect_tag != th->ec.protect_tag) {
rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier"); rb_raise(rb_eRuntimeError, "continuation called across stack rewinding barrier");
} }
if (cont->saved_thread.fiber) { if (cont->saved_thread.ec.fiber) {
if (th->fiber != cont->saved_thread.fiber) { if (th->ec.fiber != cont->saved_thread.ec.fiber) {
rb_raise(rb_eRuntimeError, "continuation called across fiber"); rb_raise(rb_eRuntimeError, "continuation called across fiber");
} }
} }
@ -1242,6 +1241,7 @@ fiber_t_alloc(VALUE fibval)
fib->cont.self = fibval; fib->cont.self = fibval;
fib->cont.type = FIBER_CONTEXT; fib->cont.type = FIBER_CONTEXT;
cont_init(&fib->cont, th); cont_init(&fib->cont, th);
fib->cont.saved_thread.ec.fiber = fib;
fib->prev = NULL; fib->prev = NULL;
/* fib->status == 0 == CREATED /* fib->status == 0 == CREATED
@ -1327,7 +1327,7 @@ void
rb_fiber_start(void) rb_fiber_start(void)
{ {
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
rb_fiber_t *fib = th->fiber; rb_fiber_t *fib = th->ec.fiber;
rb_proc_t *proc; rb_proc_t *proc;
enum ruby_tag_type state; enum ruby_tag_type state;
@ -1381,7 +1381,7 @@ root_fiber_alloc(rb_thread_t *th)
#endif #endif
#endif #endif
fiber_status_set(fib, FIBER_RESUMED); /* skip CREATED */ fiber_status_set(fib, FIBER_RESUMED); /* skip CREATED */
th->root_fiber = th->fiber = fib; th->root_fiber = th->ec.fiber = fib;
return fib; return fib;
} }
@ -1389,12 +1389,12 @@ static inline rb_fiber_t*
fiber_current(void) fiber_current(void)
{ {
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
if (th->fiber == 0) { if (th->ec.fiber == NULL) {
rb_fiber_t *fib = root_fiber_alloc(th); rb_fiber_t *fib = root_fiber_alloc(th);
/* Running thread object has stack management responsibility */ /* Running thread object has stack management responsibility */
fib->cont.saved_thread.ec.vm_stack = NULL; fib->cont.saved_thread.ec.vm_stack = NULL;
} }
return th->fiber; return th->ec.fiber;
} }
static inline rb_fiber_t* static inline rb_fiber_t*
@ -1428,8 +1428,8 @@ fiber_store(rb_fiber_t *next_fib, rb_thread_t *th)
{ {
rb_fiber_t *fib; rb_fiber_t *fib;
if (th->fiber) { if (th->ec.fiber != NULL) {
fib = th->fiber; fib = th->ec.fiber;
cont_save_thread(&fib->cont, th); cont_save_thread(&fib->cont, th);
} }
else { else {
@ -1471,7 +1471,7 @@ fiber_store(rb_fiber_t *next_fib, rb_thread_t *th)
terminated_machine_stack.size = 0; terminated_machine_stack.size = 0;
} }
#endif /* not _WIN32 */ #endif /* not _WIN32 */
fib = th->fiber; fib = th->ec.fiber;
if (fib->cont.argc == -1) rb_exc_raise(fib->cont.value); if (fib->cont.argc == -1) rb_exc_raise(fib->cont.value);
return fib->cont.value; return fib->cont.value;
@ -1502,7 +1502,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume)
rb_context_t *cont = &fib->cont; rb_context_t *cont = &fib->cont;
rb_thread_t *th = GET_THREAD(); rb_thread_t *th = GET_THREAD();
if (th->fiber == fib) { if (th->ec.fiber == fib) {
/* ignore fiber context switch /* ignore fiber context switch
* because destination fiber is same as current fiber * because destination fiber is same as current fiber
*/ */
@ -1518,7 +1518,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume)
else if (FIBER_TERMINATED_P(fib)) { else if (FIBER_TERMINATED_P(fib)) {
value = rb_exc_new2(rb_eFiberError, "dead fiber called"); 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); rb_exc_raise(value);
VM_UNREACHABLE(fiber_switch); VM_UNREACHABLE(fiber_switch);
} }
@ -1532,7 +1532,7 @@ fiber_switch(rb_fiber_t *fib, int argc, const VALUE *argv, int is_resume)
cont->argc = -1; cont->argc = -1;
cont->value = value; cont->value = value;
#if FIBER_USE_NATIVE #if FIBER_USE_NATIVE
fiber_setcontext(th->root_fiber, th->fiber); fiber_setcontext(th->root_fiber, th->ec.fiber);
#else #else
cont_restore_0(cont, &value); cont_restore_0(cont, &value);
#endif #endif
@ -1610,7 +1610,7 @@ rb_fiber_reset_root_local_storage(VALUE thval)
{ {
rb_thread_t *th = rb_thread_ptr(thval); 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; th->ec.local_storage = th->root_fiber->cont.saved_thread.ec.local_storage;
} }
} }

2
vm.c
Просмотреть файл

@ -2395,6 +2395,7 @@ rb_execution_context_mark(const rb_execution_context_t *ec)
rb_mark_tbl(ec->local_storage); rb_mark_tbl(ec->local_storage);
RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash); RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash);
RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash_for_trace); RUBY_MARK_UNLESS_NULL(ec->local_storage_recursive_hash_for_trace);
rb_fiber_mark_self(ec->fiber);
} }
void void
@ -2423,7 +2424,6 @@ rb_thread_mark(void *ptr)
RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack); RUBY_MARK_UNLESS_NULL(th->pending_interrupt_mask_stack);
RUBY_MARK_UNLESS_NULL(th->top_self); RUBY_MARK_UNLESS_NULL(th->top_self);
RUBY_MARK_UNLESS_NULL(th->top_wrapper); RUBY_MARK_UNLESS_NULL(th->top_wrapper);
rb_fiber_mark_self(th->fiber);
rb_fiber_mark_self(th->root_fiber); rb_fiber_mark_self(th->root_fiber);
RUBY_MARK_UNLESS_NULL(th->stat_insn_usage); RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
RUBY_MARK_UNLESS_NULL(th->last_status); RUBY_MARK_UNLESS_NULL(th->last_status);

Просмотреть файл

@ -765,6 +765,8 @@ typedef struct rb_execution_context_struct {
/* ensure & callcc */ /* ensure & callcc */
rb_ensure_list_t *ensure_list; rb_ensure_list_t *ensure_list;
rb_fiber_t *fiber;
} rb_execution_context_t; } rb_execution_context_t;
typedef struct rb_thread_struct { typedef struct rb_thread_struct {
@ -847,7 +849,6 @@ typedef struct rb_thread_struct {
rb_hook_list_t event_hooks; rb_hook_list_t event_hooks;
/* fiber */ /* fiber */
rb_fiber_t *fiber;
rb_fiber_t *root_fiber; rb_fiber_t *root_fiber;
rb_jmpbuf_t root_jmpbuf; rb_jmpbuf_t root_jmpbuf;