Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created January 24, 2009 23:30
Show Gist options
  • Select an option

  • Save methodmissing/51593 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/51593 to your computer and use it in GitHub Desktop.
static VALUE
rb_callcc(self)
VALUE self;
{
volatile VALUE cont;
rb_thread_t th;
volatile rb_thread_t th_save;
struct tag *tag;
struct RVarmap *vars;
THREAD_ALLOC(th);
cont = Data_Wrap_Struct(rb_cCont, thread_mark, thread_free, th);
scope_dup(ruby_scope);
for (tag=prot_tag; tag; tag=tag->prev) {
scope_dup(tag->scope);
}
th->thread = curr_thread->thread;
th->thgroup = cont_protect;
for (vars = ruby_dyna_vars; vars; vars = vars->next) {
if (FL_TEST(vars, DVAR_DONT_RECYCLE)) break;
FL_SET(vars, DVAR_DONT_RECYCLE);
}
th_save = th;
if (THREAD_SAVE_CONTEXT(th)) {
return th_save->result;
}
else {
return rb_yield(cont);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment