summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-25 02:03:44 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-08-25 02:03:44 +0000
commit977d66ec993b0f1892fb3e4cd8ac1c41716daf85 ()
tree90e36b2fb912f657c8b94278961b938c805c6dd8
parentcfaf3d9a1aee75a51f63bda5ff447da2bfc4234f (diff)
* cont.c: separate Continuation and Fiber from core.
* ext/continuation/*, ext/fiber/*: ditto. * include/ruby/ruby.h: remove rb_cFiber. * include/ruby/intern.h: add the rb_fiber_new() declaration. * enumerator.c (next_init): fix to use rb_fiber_new(). * test/ruby/test_enumerator.rb: remove next? tests. * test/ruby/test_continuation.rb: add a require 'continuation'. * test/ruby/test_fiber.rb: add a require 'fiber'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13259 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog18
-rw-r--r--cont.c61
-rw-r--r--enumerator.c2
-rw-r--r--ext/continuation/continuation.c8
-rw-r--r--ext/continuation/extconf.rb3
-rw-r--r--ext/fiber/extconf.rb3
-rw-r--r--ext/fiber/fiber.c8
-rw-r--r--include/ruby/intern.h1
-rw-r--r--include/ruby/ruby.h1
-rw-r--r--test/ruby/test_continuation.rb2
-rw-r--r--test/ruby/test_enumerator.rb11
-rw-r--r--test/ruby/test_fiber.rb5
12 files changed, 83 insertions, 40 deletions
@@ -1,3 +1,21 @@
Sat Aug 25 10:20:28 2007 Nobuyoshi Nakada <[email protected]>
* common.mk (prelude.o): depends on vm_core.h now.
@@ -34,10 +34,9 @@ typedef struct rb_context_struct {
int alive;
} rb_context_t;
-VALUE rb_cCont;
-VALUE rb_cFiber;
-VALUE rb_cFiberCore;
-VALUE rb_eFiberError;
#define GetContPtr(obj, ptr) \
Data_Get_Struct(obj, rb_context_t, ptr)
@@ -151,9 +150,6 @@ cont_new(VALUE klass)
contval = Data_Make_Struct(klass, rb_context_t,
cont_mark, cont_free, cont);
- RUBY_GC_INFO("cont alloc: %p (klass: %s)\n", cont,
- klass == rb_cFiber ? "Fiber": "Continuation");
-
cont->self = contval;
cont->alive = Qtrue;
@@ -173,7 +169,7 @@ cont_capture(volatile int *stat)
volatile VALUE contval;
vm_stack_to_heap(th);
- cont = cont_new(rb_cCont);
contval = cont->self;
sth = &cont->saved_thread;
@@ -475,6 +471,12 @@ rb_cont_call(int argc, VALUE *argv, VALUE contval)
#define FIBER_STACK_SIZE (4 * 1024)
static VALUE
rb_fiber_s_new(VALUE self)
{
@@ -590,7 +592,7 @@ rb_fiber_current()
rb_thread_t *th = GET_THREAD();
if (th->fiber == 0) {
/* save root */
- rb_context_t *cont = cont_new(rb_cFiberCore);
cont->prev = Qnil;
th->root_fiber = th->fiber = cont->self;
}
@@ -720,30 +722,29 @@ rb_fiber_s_current(VALUE klass)
void
Init_Cont(void)
{
- rb_cCont = rb_define_class("Continuation", rb_cObject);
- rb_undef_alloc_func(rb_cCont);
- rb_undef_method(CLASS_OF(rb_cCont), "new");
- rb_define_method(rb_cCont, "call", rb_cont_call, -1);
- rb_define_method(rb_cCont, "[]", rb_cont_call, -1);
- rb_define_global_function("callcc", rb_callcc, 0);
-
rb_cFiber = rb_define_class("Fiber", rb_cObject);
rb_undef_alloc_func(rb_cFiber);
- rb_define_method(rb_cFiber, "resume", rb_fiber_m_resume, -1);
- rb_define_method(rb_cFiber, "alive?", rb_fiber_alive_p, 0);
-
- rb_define_singleton_method(rb_cFiber, "current", rb_fiber_s_current, 0);
- rb_define_singleton_method(rb_cFiber, "yield", rb_fiber_s_yield, -1);
rb_define_singleton_method(rb_cFiber, "new", rb_fiber_s_new, 0);
-
- rb_cFiberCore = rb_define_class_under(rb_cFiber, "Core", rb_cObject);
- rb_undef_alloc_func(rb_cFiberCore);
- rb_define_method(rb_cFiberCore, "transfer", rb_fiber_m_transfer, -1);
- rb_define_method(rb_cFiberCore, "alive?", rb_fiber_alive_p, 0);
-
- rb_define_singleton_method(rb_cFiberCore, "current", rb_fiber_s_current, 0);
- rb_define_singleton_method(rb_cFiberCore, "new", rb_fiber_s_new, 0);
-
rb_eFiberError = rb_define_class("FiberError", rb_eStandardError);
}
@@ -391,7 +391,7 @@ next_init(VALUE obj, struct enumerator *e)
{
VALUE curr = rb_fiber_current();
e->dst = curr;
- e->fib = rb_block_call(rb_cFiber, rb_intern("new"), 0, 0, next_i, obj);
}
/*
@@ -0,0 +1,8 @@
@@ -0,0 +1,3 @@
@@ -0,0 +1,3 @@
@@ -0,0 +1,8 @@
@@ -148,6 +148,7 @@ VALUE rb_singleton_class(VALUE);
int rb_cmpint(VALUE, VALUE, VALUE);
NORETURN(void rb_cmperr(VALUE, VALUE));
/* cont.c */
VALUE rb_fiber_resume(VALUE fib, int argc, VALUE *args);
VALUE rb_fiber_yield(int argc, VALUE *args);
VALUE rb_fiber_current(void);
@@ -761,7 +761,6 @@ RUBY_EXTERN VALUE rb_cCont;
RUBY_EXTERN VALUE rb_cDir;
RUBY_EXTERN VALUE rb_cData;
RUBY_EXTERN VALUE rb_cFalseClass;
-RUBY_EXTERN VALUE rb_cFiber;
RUBY_EXTERN VALUE rb_cFile;
RUBY_EXTERN VALUE rb_cFixnum;
RUBY_EXTERN VALUE rb_cFloat;
@@ -1,4 +1,6 @@
require 'test/unit'
class TestContinuation < Test::Unit::TestCase
def test_create
@@ -24,14 +24,13 @@ class TestEnumerator < Test::Unit::TestCase
assert_raise(StopIteration){e.next}
end
- def test_next?
e = 3.times
- assert_equal true, e.next?
- 3.times{|i|
- assert_equal true, e.next?
- assert_equal i, e.next
}
- assert_equal false, e.next?
end
def test_nested_itaration
@@ -1,4 +1,5 @@
require 'test/unit'
class TestFiber < Test::Unit::TestCase
def test_normal
@@ -118,11 +119,11 @@ class TestFiber < Test::Unit::TestCase
def test_transfer
ary = []
f2 = nil
- f1 = Fiber::Core.new{
ary << f2.transfer(:foo)
:ok
}
- f2 = Fiber::Core.new{
ary << f1.transfer(:baz)
:ng
}