ruby-changes:13253
From: nobu <ko1@a...>
Date: Mon, 21 Sep 2009 10:13:40 +0900 (JST)
Subject: [ruby-changes:13253] Ruby:r25014 (trunk): * cont.c (cont_new, cont_capture, fiber_t_alloc): needs already
nobu 2009-09-21 10:13:24 +0900 (Mon, 21 Sep 2009) New Revision: 25014 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25014 Log: * cont.c (cont_new, cont_capture, fiber_t_alloc): needs already running thread. cf. [ruby-core:25681] Modified files: trunk/ChangeLog trunk/cont.c Index: ChangeLog =================================================================== --- ChangeLog (revision 25013) +++ ChangeLog (revision 25014) @@ -1,3 +1,8 @@ +Mon Sep 21 10:13:22 2009 Nobuyoshi Nakada <nobu@r...> + + * cont.c (cont_new, cont_capture, fiber_t_alloc): needs already + running thread. cf. [ruby-core:25681] + Mon Sep 21 00:07:36 2009 Nobuyoshi Nakada <nobu@r...> * ext/bigdecimal/lib/bigdecimal/math.rb (sin, cos, atan, exp, log): Index: cont.c =================================================================== --- cont.c (revision 25013) +++ cont.c (revision 25014) @@ -74,6 +74,9 @@ NOINLINE(static VALUE cont_capture(volatile int *stat)); void rb_thread_mark(rb_thread_t *th); +#define THREAD_MUST_BE_RUNNING(th) do { \ + if (!th->tag) rb_raise(rb_eThreadError, "not running thread"); \ + } while (0) static void cont_mark(void *ptr) @@ -276,10 +279,8 @@ }; static void -cont_init(rb_context_t *cont) +cont_init(rb_context_t *cont, rb_thread_t *th) { - rb_thread_t *th = GET_THREAD(); - /* save thread context */ cont->saved_thread = *th; } @@ -289,10 +290,12 @@ { rb_context_t *cont; volatile VALUE contval; + rb_thread_t *th = GET_THREAD(); + THREAD_MUST_BE_RUNNING(th); contval = TypedData_Make_Struct(klass, rb_context_t, &cont_data_type, cont); cont->self = contval; - cont_init(cont); + cont_init(cont, th); return cont; } @@ -305,6 +308,7 @@ rb_thread_t *th = GET_THREAD(), *sth; volatile VALUE contval; + THREAD_MUST_BE_RUNNING(th); rb_vm_stack_to_heap(th); cont = cont_new(rb_cContinuation); contval = cont->self; @@ -716,12 +720,15 @@ static rb_fiber_t* fiber_t_alloc(VALUE fibval) { - rb_fiber_t *fib = ALLOC(rb_fiber_t); + rb_fiber_t *fib; + rb_thread_t *th = GET_THREAD(); + THREAD_MUST_BE_RUNNING(th); + fib = ALLOC(rb_fiber_t); memset(fib, 0, sizeof(rb_fiber_t)); fib->cont.self = fibval; fib->cont.type = FIBER_CONTEXT; - cont_init(&fib->cont); + cont_init(&fib->cont, th); fib->prev = Qnil; fib->status = CREATED; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/