From c99b9eb03952284f213b714acaf7f4885ce177c2 Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 12 Sep 2018 20:49:10 +0000 Subject: share VM stack between threads and fibers if identical in size ec->vm_stack is always allocated with malloc, so stack cache for root fiber (thread stack) and non-root fibers can be shared as long as the size is the same. The purpose of this change is to reduce dependencies on ROOT_FIBER_CONTEXT. [Feature #15095] [Bug #15050] v2: vm.c: fix build with USE_THREAD_DATA_RECYCLE==0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 5c33cfb300..da9afe2fc7 100644 --- a/vm.c +++ b/vm.c @@ -2340,23 +2340,20 @@ vm_init2(rb_vm_t *vm) #define RECYCLE_MAX 64 static VALUE *thread_recycle_stack_slot[RECYCLE_MAX]; static int thread_recycle_stack_count = 0; +#endif /* USE_THREAD_DATA_RECYCLE */ -static VALUE * -thread_recycle_stack(size_t size) +VALUE * +rb_thread_recycle_stack(size_t size) { +#if USE_THREAD_DATA_RECYCLE if (thread_recycle_stack_count > 0) { /* TODO: check stack size if stack sizes are variable */ return thread_recycle_stack_slot[--thread_recycle_stack_count]; } - else { - return ALLOC_N(VALUE, size); - } +#endif /* USE_THREAD_DATA_RECYCLE */ + return ALLOC_N(VALUE, size); } -#else -#define thread_recycle_stack(size) ALLOC_N(VALUE, (size)) -#endif - void rb_thread_recycle_stack_release(VALUE *stack) { @@ -2536,7 +2533,7 @@ th_init(rb_thread_t *th, VALUE self) /* vm_stack_size is word number. * th->vm->default_params.thread_vm_stack_size is byte size. */ size_t size = th->vm->default_params.thread_vm_stack_size / sizeof(VALUE); - ec_set_vm_stack(th->ec, thread_recycle_stack(size), size); + ec_set_vm_stack(th->ec, rb_thread_recycle_stack(size), size); } th->ec->cfp = (void *)(th->ec->vm_stack + th->ec->vm_stack_size); -- cgit v1.2.3