summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-02 21:48:51 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-02 21:48:51 +0000
commit46085e913a90e2c9b3c7b01d8aea91cd43e76224 (patch)
treeb9ecda477c941969c06b55f917caf4485da141e5 /cont.c
parenta2078e7c54a178a7cf107ad8749b0a0c32e96f6b (diff)
fix stack storing for root fibers.
* cont.c (root_fiber_alloc): this function is called by fiber_current() and fiber_store(). fiber_current() should clear VM stack information in a fiber data because runnning thread knows stack information and has responsibility to manage it. However fiber_store() requires to remain VM stack information in a fiber data because the responsibility to manage VM stack is moved to the Fiber from the Thread (and switch to another fiber). * cont.c (root_fiber_alloc): save thread's fiber and root_fiber information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/cont.c b/cont.c
index a43950c6cb..7483c1c476 100644
--- a/cont.c
+++ b/cont.c
@@ -556,6 +556,7 @@ cont_restore_thread(rb_context_t *cont)
th->fiber = (rb_fiber_t*)cont;
}
+ VM_ASSERT(th->ec.stack != NULL);
VM_ASSERT(sth->status == THREAD_RUNNABLE);
}
@@ -1288,7 +1289,6 @@ root_fiber_alloc(rb_thread_t *th)
rb_fiber_t *fib;
/* no need to allocate vm stack */
fib = fiber_t_alloc(fiber_alloc(rb_cFiber));
- fib->cont.saved_thread.ec.stack = NULL;
fib->cont.type = ROOT_FIBER_CONTEXT;
#if FIBER_USE_NATIVE
#ifdef _WIN32
@@ -1297,6 +1297,7 @@ root_fiber_alloc(rb_thread_t *th)
#endif
fib->status = FIBER_RUNNING;
+ th->root_fiber = th->fiber = fib;
return fib;
}
@@ -1305,9 +1306,9 @@ fiber_current(void)
{
rb_thread_t *th = GET_THREAD();
if (th->fiber == 0) {
- /* save root */
rb_fiber_t *fib = root_fiber_alloc(th);
- th->root_fiber = th->fiber = fib;
+ /* Running thread object has stack management responsibility */
+ fib->cont.saved_thread.ec.stack = NULL;
}
return th->fiber;
}
@@ -1348,9 +1349,8 @@ fiber_store(rb_fiber_t *next_fib, rb_thread_t *th)
cont_save_thread(&fib->cont, th);
}
else {
- /* create current fiber */
+ /* create root fiber */
fib = root_fiber_alloc(th);
- th->root_fiber = th->fiber = fib;
}
#if FIBER_USE_NATIVE