garbage collect context (fiber) properly

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-05-22 11:05:22 +09:00
parent 1cfd3fb9eb
commit 2045a35292
3 changed files with 8 additions and 3 deletions
+2
View File
@@ -74,6 +74,8 @@ struct mrb_context {
int rsize;
struct RProc **ensure;
int esize;
struct RFiber *fib;
};
enum gc_state {
+3 -1
View File
@@ -80,9 +80,9 @@ fiber_init(mrb_state *mrb, mrb_value self)
f->cxt = (struct mrb_context*)mrb_malloc(mrb, sizeof(struct mrb_context));
*f->cxt = mrb_context_zero;
c = f->cxt;
/* initialize VM stack */
c = f->cxt;
c->stbase = (mrb_value *)mrb_calloc(mrb, FIBER_STACK_INIT_SIZE, sizeof(mrb_value));
c->stend = c->stbase + FIBER_STACK_INIT_SIZE;
c->stack = c->stbase;
@@ -104,6 +104,8 @@ fiber_init(mrb_state *mrb, mrb_value self)
ci[1] = ci[0];
c->ci++; /* push dummy callinfo */
c->fib = f;
return self;
}
+3 -2
View File
@@ -412,7 +412,9 @@ mark_context(mrb_state *mrb, struct mrb_context *c)
mrb_gc_mark(mrb, (struct RBasic*)ci->proc);
mrb_gc_mark(mrb, (struct RBasic*)ci->target_class);
}
if (c->prev) mark_context(mrb, c->prev);
if (c->prev && c->prev->fib) {
mrb_gc_mark(mrb, (struct RBasic*)c->prev->fib);
}
}
static void
@@ -472,7 +474,6 @@ gc_mark_children(mrb_state *mrb, struct RBasic *obj)
struct mrb_context *c = ((struct RFiber*)obj)->cxt;
mark_context(mrb, c);
((struct RFiber*)obj)->cxt = NULL;
}
break;