mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
introduce rb_fiber_t::first_proc.
* cont.c (rb_fiber_t): add rb_fiber_t::first_proc and do not use rb_thread_t::first_proc which should be thread local. [Bug #13689] * test/ruby/test_thread.rb: test for [Bug #13689]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8dd9c12c58
commit
5041f548dd
2 changed files with 18 additions and 6 deletions
11
cont.c
11
cont.c
|
@ -125,6 +125,7 @@ static machine_stack_cache_t terminated_machine_stack;
|
||||||
|
|
||||||
struct rb_fiber_struct {
|
struct rb_fiber_struct {
|
||||||
rb_context_t cont;
|
rb_context_t cont;
|
||||||
|
VALUE first_proc;
|
||||||
struct rb_fiber_struct *prev;
|
struct rb_fiber_struct *prev;
|
||||||
enum fiber_status status;
|
enum fiber_status status;
|
||||||
/* If a fiber invokes "transfer",
|
/* If a fiber invokes "transfer",
|
||||||
|
@ -308,6 +309,7 @@ fiber_mark(void *ptr)
|
||||||
{
|
{
|
||||||
rb_fiber_t *fib = ptr;
|
rb_fiber_t *fib = ptr;
|
||||||
RUBY_MARK_ENTER("cont");
|
RUBY_MARK_ENTER("cont");
|
||||||
|
rb_gc_mark(fib->first_proc);
|
||||||
rb_fiber_mark_self(fib->prev);
|
rb_fiber_mark_self(fib->prev);
|
||||||
cont_mark(&fib->cont);
|
cont_mark(&fib->cont);
|
||||||
RUBY_MARK_LEAVE("cont");
|
RUBY_MARK_LEAVE("cont");
|
||||||
|
@ -412,7 +414,6 @@ cont_save_thread(rb_context_t *cont, rb_thread_t *th)
|
||||||
|
|
||||||
/* save thread context */
|
/* save thread context */
|
||||||
sth->ec = th->ec;
|
sth->ec = th->ec;
|
||||||
sth->first_proc = th->first_proc;
|
|
||||||
|
|
||||||
/* saved_thread->machine.stack_(start|end) should be NULL */
|
/* saved_thread->machine.stack_(start|end) should be NULL */
|
||||||
/* because it may happen GC afterward */
|
/* because it may happen GC afterward */
|
||||||
|
@ -555,8 +556,6 @@ cont_restore_thread(rb_context_t *cont)
|
||||||
th->fiber = (rb_fiber_t*)cont;
|
th->fiber = (rb_fiber_t*)cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
th->first_proc = sth->first_proc;
|
|
||||||
|
|
||||||
VM_ASSERT(sth->status == THREAD_RUNNABLE);
|
VM_ASSERT(sth->status == THREAD_RUNNABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,7 +1216,7 @@ fiber_init(VALUE fibval, VALUE proc)
|
||||||
th->ec.local_storage_recursive_hash = Qnil;
|
th->ec.local_storage_recursive_hash = Qnil;
|
||||||
th->ec.local_storage_recursive_hash_for_trace = Qnil;
|
th->ec.local_storage_recursive_hash_for_trace = Qnil;
|
||||||
|
|
||||||
th->first_proc = proc;
|
fib->first_proc = proc;
|
||||||
|
|
||||||
#if !FIBER_USE_NATIVE
|
#if !FIBER_USE_NATIVE
|
||||||
MEMCPY(&cont->jmpbuf, &cth->root_jmpbuf, rb_jmpbuf_t, 1);
|
MEMCPY(&cont->jmpbuf, &cth->root_jmpbuf, rb_jmpbuf_t, 1);
|
||||||
|
@ -1254,11 +1253,11 @@ rb_fiber_start(void)
|
||||||
rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont;
|
rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont;
|
||||||
int argc;
|
int argc;
|
||||||
const VALUE *argv, args = cont->value;
|
const VALUE *argv, args = cont->value;
|
||||||
GetProcPtr(cont->saved_thread.first_proc, proc);
|
GetProcPtr(fib->first_proc, proc);
|
||||||
argv = (argc = cont->argc) > 1 ? RARRAY_CONST_PTR(args) : &args;
|
argv = (argc = cont->argc) > 1 ? RARRAY_CONST_PTR(args) : &args;
|
||||||
cont->value = Qnil;
|
cont->value = Qnil;
|
||||||
th->ec.errinfo = Qnil;
|
th->ec.errinfo = Qnil;
|
||||||
th->ec.root_lep = rb_vm_proc_local_ep(cont->saved_thread.first_proc);
|
th->ec.root_lep = rb_vm_proc_local_ep(fib->first_proc);
|
||||||
th->ec.root_svar = Qfalse;
|
th->ec.root_svar = Qfalse;
|
||||||
fib->status = FIBER_RUNNING;
|
fib->status = FIBER_RUNNING;
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,19 @@ class TestThread < Test::Unit::TestCase
|
||||||
th.join
|
th.join
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_inspect_with_fiber
|
||||||
|
inspect1 = inspect2 = nil
|
||||||
|
|
||||||
|
Thread.new{
|
||||||
|
inspect1 = Thread.current.inspect
|
||||||
|
Fiber.new{
|
||||||
|
inspect2 = Thread.current.inspect
|
||||||
|
}.resume
|
||||||
|
}.join
|
||||||
|
|
||||||
|
assert_equal inspect1, inspect2, '[Bug #13689]'
|
||||||
|
end
|
||||||
|
|
||||||
def test_main_thread_variable_in_enumerator
|
def test_main_thread_variable_in_enumerator
|
||||||
assert_equal Thread.main, Thread.current
|
assert_equal Thread.main, Thread.current
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue