diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2019-06-05 18:23:04 +1200 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2019-06-19 20:39:10 +1200 |
commit | 38791145ebc6890b97ea55ee490084c63b67f3cc (patch) | |
tree | 8f5e77f663df93c1ae69ea4aeba0d4b7b3ac79fb | |
parent | 7c7a1c221281cdba1f48d5e42ee2f9af306d27f8 (diff) | |
download | ruby-38791145ebc6890b97ea55ee490084c63b67f3cc.tar.gz |
Better handling of root fiber.
-rw-r--r-- | cont.c | 7 | ||||
-rw-r--r-- | thread.c | 27 | ||||
-rw-r--r-- | vm.c | 2 |
3 files changed, 18 insertions, 18 deletions
@@ -420,10 +420,7 @@ cont_free(void *ptr) rb_fiber_t *fib = (rb_fiber_t*)cont; #if defined(FIBER_USE_COROUTINE) coroutine_destroy(&fib->context); - if (fib->ss_sp != NULL) { - if (fiber_is_root_p(fib)) { - rb_bug("Illegal root fiber parameter"); - } + if (fib->ss_sp != NULL && !fiber_is_root_p(fib)) { #ifdef _WIN32 VirtualFree((void*)fib->ss_sp, 0, MEM_RELEASE); #else @@ -1661,6 +1658,8 @@ rb_threadptr_root_fiber_setup(rb_thread_t *th) fiber_status_set(fib, FIBER_RESUMED); /* skip CREATED */ th->ec = &fib->cont.saved_ec; + th->root_fiber = fib; + /* NOTE: On WIN32, fib_handle is not allocated yet. */ } @@ -714,29 +714,30 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s rb_thread_list_t *join_list; rb_thread_t *main_th; VALUE errinfo = Qnil; + VALUE * vm_stack = NULL; + size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE); if (th == th->vm->main_thread) { rb_bug("thread_start_func_2 must not be used for main thread"); } - { - size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE); - rb_ec_set_vm_stack(th->ec, alloca(size * sizeof(VALUE)), size); + vm_stack = alloca(size * sizeof(VALUE)); + rb_ec_set_vm_stack(th->ec, vm_stack, size); - th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size); + th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size); - rb_vm_push_frame(th->ec, - 0 /* dummy iseq */, - VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */, - Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */, - 0 /* dummy cref/me */, - 0 /* dummy pc */, th->ec->vm_stack, 0, 0 - ); - } + rb_vm_push_frame(th->ec, + 0 /* dummy iseq */, + VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_CFRAME /* dummy frame */, + Qnil /* dummy self */, VM_BLOCK_HANDLER_NONE /* dummy block ptr */, + 0 /* dummy cref/me */, + 0 /* dummy pc */, th->ec->vm_stack, 0, 0 + ); ruby_thread_set_native(th); - th->ec->machine.stack_start = stack_start; + th->ec->machine.stack_start = vm_stack; + th->ec->machine.stack_maxsize = th->ec->machine.stack_end - th->ec->machine.stack_start; #ifdef __ia64 th->ec->machine.register_stack_start = register_stack_start; #endif @@ -2625,7 +2625,7 @@ thread_free(void *ptr) rb_bug("thread_free: keeping_mutexes must be NULL (%p:%p)", (void *)th, (void *)th->keeping_mutexes); } - //rb_threadptr_root_fiber_release(th); + rb_threadptr_root_fiber_release(th); if (th->vm && th->vm->main_thread == th) { RUBY_GC_INFO("main thread\n"); |