mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
introduce fiber_restore_thread.
* cont.c (fiber_restore_thread): added (separate from cont_restore_thread). * cont.c (fiber_setcontext): call fiber_restore_thread() directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
157ee2bdbc
commit
404284674a
1 changed files with 21 additions and 8 deletions
29
cont.c
29
cont.c
|
@ -577,14 +577,29 @@ cont_capture(volatile int *volatile stat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
static inline void
|
||||||
cont_restore_thread(rb_context_t *cont)
|
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 */
|
/* restore thread context */
|
||||||
if (cont->type == CONTINUATION_CONTEXT) {
|
if (cont->type == CONTINUATION_CONTEXT) {
|
||||||
/* continuation */
|
/* continuation */
|
||||||
|
rb_thread_t *sth = &cont->saved_thread;
|
||||||
const rb_fiber_t *fib;
|
const rb_fiber_t *fib;
|
||||||
|
|
||||||
th->fiber = sth->fiber;
|
th->fiber = sth->fiber;
|
||||||
|
@ -613,16 +628,14 @@ cont_restore_thread(rb_context_t *cont)
|
||||||
th->ec.ensure_list = sth->ec.ensure_list;
|
th->ec.ensure_list = sth->ec.ensure_list;
|
||||||
th->ec.errinfo = sth->ec.errinfo;
|
th->ec.errinfo = sth->ec.errinfo;
|
||||||
th->ec.trace_arg = sth->ec.trace_arg;
|
th->ec.trace_arg = sth->ec.trace_arg;
|
||||||
|
|
||||||
|
VM_ASSERT(th->ec.vm_stack != NULL);
|
||||||
|
VM_ASSERT(sth->status == THREAD_RUNNABLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* fiber */
|
/* fiber */
|
||||||
th->ec = sth->ec;
|
fiber_restore_thread(th, (rb_fiber_t*)cont);
|
||||||
sth->ec.vm_stack = NULL;
|
|
||||||
th->fiber = (rb_fiber_t*)cont;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VM_ASSERT(th->ec.vm_stack != NULL);
|
|
||||||
VM_ASSERT(sth->status == THREAD_RUNNABLE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FIBER_USE_NATIVE
|
#if FIBER_USE_NATIVE
|
||||||
|
@ -743,7 +756,7 @@ fiber_setcontext(rb_fiber_t *newfib, rb_fiber_t *oldfib)
|
||||||
rb_thread_t *th = GET_THREAD(), *sth = &newfib->cont.saved_thread;
|
rb_thread_t *th = GET_THREAD(), *sth = &newfib->cont.saved_thread;
|
||||||
|
|
||||||
/* restore thread context */
|
/* restore thread context */
|
||||||
cont_restore_thread(&newfib->cont);
|
fiber_restore_thread(th, newfib);
|
||||||
th->machine.stack_maxsize = sth->machine.stack_maxsize;
|
th->machine.stack_maxsize = sth->machine.stack_maxsize;
|
||||||
if (sth->machine.stack_end && (newfib != oldfib)) {
|
if (sth->machine.stack_end && (newfib != oldfib)) {
|
||||||
rb_bug("fiber_setcontext: sth->machine.stack_end has non zero value");
|
rb_bug("fiber_setcontext: sth->machine.stack_end has non zero value");
|
||||||
|
|
Loading…
Reference in a new issue