From 8cdf5c417993f453149365f76c46f28e0bb4fa8f Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 15 Feb 2012 22:34:48 +0000 Subject: merge revision(s) 34629,34630: * cont.c (rb_fiber_reset_root_local_storage): add a new function to restore rb_thread_t::local_storage. * cont.c (rb_obj_is_fiber): add a new function to tell finalizer to prevent fibers from destroy. * gc.c (rb_objspace_call_finalizer): don't sweep fibers at finalizing objspace. * internal.h (rb_fiber_reset_root_local_storage, rb_obj_is_fiber): add prototypes. * vm.c (ruby_vm_destruct): reset main thread's local_storage before free main thread. rb_thread_t::local_storage is replaced by fiber's local storage when forked from fiber, and it should be already freed when the fiber was destroyed. * test/ruby/test_fiber.rb (test_fork_from_fiber): add test for fork from fiber. when the fiber was destroyed. [ruby-core:41456] [Bug #5700] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34637 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- cont.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cont.c') diff --git a/cont.c b/cont.c index 76146179b6..1e42974145 100644 --- a/cont.c +++ b/cont.c @@ -324,6 +324,17 @@ fiber_memsize(const void *ptr) return size; } +VALUE +rb_obj_is_fiber(VALUE obj) +{ + if (rb_typeddata_is_kind_of(obj, &fiber_data_type)) { + return Qtrue; + } + else { + return Qfalse; + } +} + static void cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont) { @@ -1342,6 +1353,19 @@ rb_fiber_yield(int argc, VALUE *argv) return rb_fiber_transfer(return_fiber(), argc, argv); } +void +rb_fiber_reset_root_local_storage(VALUE thval) +{ + rb_thread_t *th; + rb_fiber_t *fib; + + GetThreadPtr(thval, th); + if (th->root_fiber && th->root_fiber != th->fiber) { + GetFiberPtr(th->root_fiber, fib); + th->local_storage = fib->cont.saved_thread.local_storage; + } +} + /* * call-seq: * fiber.alive? -> true or false -- cgit v1.2.3