summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-06 18:19:42 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-06-06 18:19:42 +0000
commitd80e7373cfb0ca1558bdeb79643c53db5f9ce4d8 (patch)
treea0f9bd31081dda1430be6d7df5649515832c8835 /cont.c
parented8897523701745467cf831ff19ec3268856cf6e (diff)
* cont.c (cont_new): add debug message.
* cont.c (cont_restore_1): copy stack information from fiber. * cont.c (rb_fiber_s_new): fix to mark created fiber. * test/ruby/test_fiber.rb: add some tests around Thread and Fiber. * yarvcore.c (thread_free): fix to skip freeing stack if root fiber is available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/cont.c b/cont.c
index 8c2508a094..4210ab97d5 100644
--- a/cont.c
+++ b/cont.c
@@ -111,6 +111,10 @@ cont_new(VALUE klass)
contval = Data_Make_Struct(klass, rb_context_t,
cont_mark, cont_free, cont);
+
+ GC_INFO("cont alloc: %p (klass: %s)\n", cont,
+ klass == rb_cFiber ? "Fiber": "Continuation");
+
cont->self = contval;
cont->alive = Qtrue;
@@ -169,8 +173,15 @@ cont_restore_1(rb_context_t *cont)
}
else {
/* continuation */
- MEMCPY(th->stack, cont->vm_stack, VALUE, sth->stack_size);
th->fiber = sth->fiber;
+
+ if (th->fiber) {
+ rb_context_t *fcont;
+ GetContPtr(th->fiber, fcont);
+ th->stack_size = fcont->saved_thread.stack_size;
+ th->stack = fcont->saved_thread.stack;
+ }
+ MEMCPY(th->stack, cont->vm_stack, VALUE, sth->stack_size);
}
th->cfp = sth->cfp;
@@ -369,6 +380,7 @@ static VALUE
rb_fiber_s_new(VALUE self)
{
rb_context_t *cont = cont_new(self);
+ VALUE contval = cont->self;
rb_thread_t *th = &cont->saved_thread;
/* initialize */
@@ -396,7 +408,7 @@ rb_fiber_s_new(VALUE self)
MEMCPY(&cont->jmpbuf, &th->root_jmpbuf, rb_jmpbuf_t, 1);
- return cont->self;
+ return contval;
}
static VALUE rb_fiber_yield(int argc, VALUE *args, VALUE fval);