aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-08 06:21:30 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-08 06:21:30 +0000
commitfc6eff20effda4da48d8ccb34616387cd8c51bbe (patch)
treea82c73fdc44e7a767cb22e6e2d5f36ec5aa98ce2
parentedf36be8a3b4b0a13babedbcb468fee1d0afb6a1 (diff)
downloadruby-fc6eff20effda4da48d8ccb34616387cd8c51bbe.tar.gz
move th->fiber to ec->fiber.
* 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
-rw-r--r--cont.c40
-rw-r--r--vm.c2
-rw-r--r--vm_core.h3
3 files changed, 23 insertions, 22 deletions
diff --git a/cont.c b/cont.c
index b27afc2158..abfc1c384c 100644
--- a/cont.c
+++ b/cont.c
@@ -248,7 +248,7 @@ cont_mark(void *ptr)
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)
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_t *th)
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_fiber_t *fib)
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)
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, VALUE contval)
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)
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
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)
#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*
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_thread_t *th)
{
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_thread_t *th)
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, const VALUE *argv, int is_resume)
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, const VALUE *argv, int is_resume)
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, const VALUE *argv, int is_resume)
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 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;
}
}
diff --git a/vm.c b/vm.c
index 74229e3c6c..5569b87182 100644
--- a/vm.c
+++ b/vm.c
@@ -2395,6 +2395,7 @@ rb_execution_context_mark(const rb_execution_context_t *ec)
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)
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);
diff --git a/vm_core.h b/vm_core.h
index 3d44a3abef..a2ca6342cf 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -765,6 +765,8 @@ typedef struct rb_execution_context_struct {
/* 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 {
rb_hook_list_t event_hooks;
/* fiber */
- rb_fiber_t *fiber;
rb_fiber_t *root_fiber;
rb_jmpbuf_t root_jmpbuf;