summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-21 01:13:24 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-21 01:13:24 +0000
commit3a7c1e25c4f88d6cdfc6c9978aa6811dc548119b (patch)
tree6e6b424abf1d1c8dff1cbdf185ebd2a399675ba5
parentcd4f59bc5e32c71fcef679ebdbd750c7d2ed5f5e (diff)
* cont.c (cont_new, cont_capture, fiber_t_alloc): needs already
running thread. cf. [ruby-core:25681] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--cont.c19
2 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index db8fed2c061..d51cb559fed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Sep 21 10:13:22 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* ext/bigdecimal/lib/bigdecimal/math.rb (sin, cos, atan, exp, log):
diff --git a/cont.c b/cont.c
index 996328c5540..eefce6d7bd3 100644
--- a/cont.c
+++ b/cont.c
@@ -74,6 +74,9 @@ static VALUE rb_eFiberError;
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 const rb_data_type_t cont_data_type = {
};
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 @@ cont_new(VALUE klass)
{
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 @@ cont_capture(volatile int *stat)
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 @@ fiber_alloc(VALUE klass)
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;