зеркало из https://github.com/github/ruby.git
* vm.c: fix to recycle thread data (VM stack).
* thread.c: ditto. * benchmark/bm_vm3_thread_create_join.rb: add loop count. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
58b1f91b46
Коммит
c79ab68d37
|
@ -1,3 +1,11 @@
|
||||||
|
Wed Nov 21 18:03:49 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* vm.c: fix to recycle thread data (VM stack).
|
||||||
|
|
||||||
|
* thread.c: ditto.
|
||||||
|
|
||||||
|
* benchmark/bm_vm3_thread_create_join.rb: add loop count.
|
||||||
|
|
||||||
Wed Nov 21 18:02:10 2007 Koichi Sasada <ko1@atdot.net>
|
Wed Nov 21 18:02:10 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* benchmark/driver.rb: add path to trunk/lib if driver runner is
|
* benchmark/driver.rb: add path to trunk/lib if driver runner is
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
i=0
|
i=0
|
||||||
while i<1000 # benchmark loop 3
|
while i<100_000 # benchmark loop 3
|
||||||
i+=1
|
i+=1
|
||||||
Thread.new{
|
Thread.new{
|
||||||
}.join
|
}.join
|
||||||
|
|
7
thread.c
7
thread.c
|
@ -288,6 +288,7 @@ thread_cleanup_func(void *th_ptr)
|
||||||
|
|
||||||
extern void ruby_error_print(void);
|
extern void ruby_error_print(void);
|
||||||
static VALUE rb_thread_raise(int, VALUE *, rb_thread_t *);
|
static VALUE rb_thread_raise(int, VALUE *, rb_thread_t *);
|
||||||
|
void rb_thread_recycle_stack_release(VALUE *);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)
|
thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_start)
|
||||||
|
@ -359,6 +360,11 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start, VALUE *register_stack_s
|
||||||
join_th = join_th->join_list_next;
|
join_th = join_th->join_list_next;
|
||||||
}
|
}
|
||||||
st_delete_wrap(th->vm->living_threads, th->self);
|
st_delete_wrap(th->vm->living_threads, th->self);
|
||||||
|
|
||||||
|
if (!th->root_fiber) {
|
||||||
|
rb_thread_recycle_stack_release(th->stack);
|
||||||
|
th->stack = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
thread_cleanup_func(th);
|
thread_cleanup_func(th);
|
||||||
native_mutex_unlock(&th->vm->global_interpreter_lock);
|
native_mutex_unlock(&th->vm->global_interpreter_lock);
|
||||||
|
@ -428,7 +434,6 @@ thread_join(rb_thread_t *target_th, double delay)
|
||||||
th->join_list_next = target_th->join_list_head;
|
th->join_list_next = target_th->join_list_head;
|
||||||
target_th->join_list_head = th;
|
target_th->join_list_head = th;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (target_th->status != THREAD_KILLED) {
|
while (target_th->status != THREAD_KILLED) {
|
||||||
if (delay == DELAY_INFTY) {
|
if (delay == DELAY_INFTY) {
|
||||||
sleep_forever(th);
|
sleep_forever(th);
|
||||||
|
|
52
vm.c
52
vm.c
|
@ -1521,6 +1521,51 @@ vm_init2(rb_vm_t *vm)
|
||||||
|
|
||||||
/* Thread */
|
/* Thread */
|
||||||
|
|
||||||
|
#define USE_THREAD_DATA_RECYCLE 1
|
||||||
|
|
||||||
|
#if USE_THREAD_DATA_RECYCLE
|
||||||
|
#define RECYCLE_MAX 64
|
||||||
|
VALUE *thread_recycle_stack_slot[RECYCLE_MAX];
|
||||||
|
int thread_recycle_stack_count = 0;
|
||||||
|
|
||||||
|
static VALUE *
|
||||||
|
thread_recycle_stack(int size)
|
||||||
|
{
|
||||||
|
if (thread_recycle_stack_count) {
|
||||||
|
return thread_recycle_stack_slot[--thread_recycle_stack_count];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ALLOC_N(VALUE, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define thread_recycle_stack(size) ALLOC_N(VALUE, (size))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_thread_recycle_stack_release(VALUE *stack)
|
||||||
|
{
|
||||||
|
#if USE_THREAD_DATA_RECYCLE
|
||||||
|
if (thread_recycle_stack_count < RECYCLE_MAX) {
|
||||||
|
thread_recycle_stack_slot[thread_recycle_stack_count++] = stack;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ruby_xfree(stack);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
ruby_xfree(stack);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static rb_thread_t *
|
||||||
|
thread_recycle_struct(void)
|
||||||
|
{
|
||||||
|
void *p = ALLOC_N(rb_thread_t, 1);
|
||||||
|
memset(p, 0, sizeof(rb_thread_t));
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
thread_free(void *ptr)
|
thread_free(void *ptr)
|
||||||
{
|
{
|
||||||
|
@ -1619,6 +1664,8 @@ static VALUE
|
||||||
thread_alloc(VALUE klass)
|
thread_alloc(VALUE klass)
|
||||||
{
|
{
|
||||||
VALUE volatile obj;
|
VALUE volatile obj;
|
||||||
|
//rb_thread_t *th = thread_recycle_struct();
|
||||||
|
//obj = Data_Wrap_Struct(klass, rb_thread_mark, thread_free, th);
|
||||||
rb_thread_t *th;
|
rb_thread_t *th;
|
||||||
obj = Data_Make_Struct(klass, rb_thread_t,
|
obj = Data_Make_Struct(klass, rb_thread_t,
|
||||||
rb_thread_mark, thread_free, th);
|
rb_thread_mark, thread_free, th);
|
||||||
|
@ -1628,11 +1675,9 @@ thread_alloc(VALUE klass)
|
||||||
static void
|
static void
|
||||||
th_init2(rb_thread_t *th)
|
th_init2(rb_thread_t *th)
|
||||||
{
|
{
|
||||||
MEMZERO(th, rb_thread_t, 1);
|
|
||||||
|
|
||||||
/* allocate thread stack */
|
/* allocate thread stack */
|
||||||
th->stack_size = RUBY_VM_THREAD_STACK_SIZE;
|
th->stack_size = RUBY_VM_THREAD_STACK_SIZE;
|
||||||
th->stack = ALLOC_N(VALUE, th->stack_size);
|
th->stack = thread_recycle_stack(th->stack_size);
|
||||||
|
|
||||||
th->cfp = (void *)(th->stack + th->stack_size);
|
th->cfp = (void *)(th->stack + th->stack_size);
|
||||||
th->cfp--;
|
th->cfp--;
|
||||||
|
@ -1815,6 +1860,7 @@ Init_BareVM(void)
|
||||||
/* VM bootstrap: phase 1 */
|
/* VM bootstrap: phase 1 */
|
||||||
rb_vm_t *vm = ALLOC(rb_vm_t);
|
rb_vm_t *vm = ALLOC(rb_vm_t);
|
||||||
rb_thread_t *th = ALLOC(rb_thread_t);
|
rb_thread_t *th = ALLOC(rb_thread_t);
|
||||||
|
MEMZERO(th, rb_thread_t, 1);
|
||||||
|
|
||||||
vm_init2(vm);
|
vm_init2(vm);
|
||||||
ruby_current_vm = vm;
|
ruby_current_vm = vm;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче