* vm_core.h (rb_thread_t#yielding): add a field.

* thread.c (rb_thread_schedule_limits): set th#yielding while
  release GVL to yield CPU time.
* thread.c (timer_thread_function): skip timer interrupt when
  th#yielding is true.  This patch fixes r35480.
* thread.c (rb_threadptr_execute_interrupts_common): revert
  a patch of r35480.
* ChangeLog: add an extended memo of r35480.
  http://bugs.ruby-lang.org/projects/ruby-trunk/wiki/R35480_ExtendedMemo



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2012-04-28 09:59:44 +00:00
Родитель 62d71852df
Коммит 6978b8ca67
3 изменённых файлов: 23 добавлений и 7 удалений

Просмотреть файл

@ -1,3 +1,19 @@
Sat Apr 28 18:39:40 2012 Koichi Sasada <ko1@atdot.net>
* vm_core.h (rb_thread_t#yielding): add a field.
* thread.c (rb_thread_schedule_limits): set th#yielding while
release GVL to yield CPU time.
* thread.c (timer_thread_function): skip timer interrupt when
th#yielding is true. This patch fixes r35480.
* thread.c (rb_threadptr_execute_interrupts_common): revert
a patch of r35480.
* ChangeLog: add an extended memo of r35480.
http://bugs.ruby-lang.org/projects/ruby-trunk/wiki/R35480_ExtendedMemo
Fri Apr 27 12:34:23 2012 NAKAMURA Usaku <usa@ruby-lang.org> Fri Apr 27 12:34:23 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/dl/cfunc.c (rb_dlcfunc_call): should convert a Bignum value to * ext/dl/cfunc.c (rb_dlcfunc_call): should convert a Bignum value to
@ -39,6 +55,7 @@ Fri Apr 27 01:45:05 2012 NARUSE, Yui <naruse@ruby-lang.org>
(22) main thread waits at gvl_yield:112 (native_cond_wait) (22) main thread waits at gvl_yield:112 (native_cond_wait)
As described above, the main thread can't escape from As described above, the main thread can't escape from
rb_threadptr_execute_interrupts_common. rb_threadptr_execute_interrupts_common.
See extended memo: http://bugs.ruby-lang.org/projects/ruby-trunk/wiki/R35480_ExtendedMemo
Fri Apr 27 07:15:07 2012 Tanaka Akira <akr@fsij.org> Fri Apr 27 07:15:07 2012 Tanaka Akira <akr@fsij.org>

Просмотреть файл

@ -1021,8 +1021,10 @@ rb_thread_schedule_limits(unsigned long limits_us)
if (th->running_time_us >= limits_us) { if (th->running_time_us >= limits_us) {
thread_debug("rb_thread_schedule/switch start\n"); thread_debug("rb_thread_schedule/switch start\n");
th->yielding = 1;
RB_GC_SAVE_MACHINE_CONTEXT(th); RB_GC_SAVE_MACHINE_CONTEXT(th);
gvl_yield(th->vm, th); gvl_yield(th->vm, th);
th->yielding = 0;
rb_thread_set_current(th); rb_thread_set_current(th);
thread_debug("rb_thread_schedule/switch done\n"); thread_debug("rb_thread_schedule/switch done\n");
} }
@ -1273,7 +1275,6 @@ static void
rb_threadptr_execute_interrupts_common(rb_thread_t *th) rb_threadptr_execute_interrupts_common(rb_thread_t *th)
{ {
rb_atomic_t interrupt; rb_atomic_t interrupt;
int first_p = TRUE;
if (th->raised_flag) return; if (th->raised_flag) return;
@ -1283,11 +1284,6 @@ rb_threadptr_execute_interrupts_common(rb_thread_t *th)
int finalizer_interrupt = interrupt & 0x04; int finalizer_interrupt = interrupt & 0x04;
int sig; int sig;
if (first_p)
first_p = FALSE;
else if (interrupt == 0x01)
break;
th->status = THREAD_RUNNABLE; th->status = THREAD_RUNNABLE;
/* signal handling */ /* signal handling */
@ -2939,7 +2935,9 @@ timer_thread_function(void *arg)
rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */ rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */
/* for time slice */ /* for time slice */
RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread); if (!vm->running_thread->yielding) {
RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread);
}
/* check signal */ /* check signal */
rb_threadptr_check_signal(vm->main_thread); rb_threadptr_check_signal(vm->main_thread);

Просмотреть файл

@ -407,6 +407,7 @@ typedef struct rb_thread_struct {
/* passing state */ /* passing state */
int state; int state;
int yielding;
int waiting_fd; int waiting_fd;