Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Fri Sep 14 17:30:14 2012 KOSAKI Motohiro <[email protected]>

* thread.c (timer_thread_function): fixed a race against thread
context switch.
* thread.c (clear_timer_interrupt): new helper function.

Mon Sep 10 10:19:34 2012 NAKAMURA Usaku <[email protected]>

* enc/depend: fixed wrong change in a part of r34802.
Expand Down
29 changes: 26 additions & 3 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -3382,16 +3382,39 @@ rb_threadptr_check_signal(rb_thread_t *mth)
}
}

static void
clear_timer_interrupt(rb_thread_t *th)
{
rb_atomic_t interrupt;
rb_atomic_t old;

do {
interrupt = th->interrupt_flag;
old = ATOMIC_EXCHANGE(th->interrupt_flag, interrupt & ~0x01);
} while (interrupt != old);

}


static void
timer_thread_function(void *arg)
{
rb_vm_t *vm = GET_VM(); /* TODO: fix me for Multi-VM */

/* for time slice */
if (!vm->running_thread->yielding) {
RUBY_VM_SET_TIMER_INTERRUPT(vm->running_thread);
while (1) {
rb_thread_t *running = vm->running_thread;

/* for time slice */
if (!vm->running_thread->yielding)
RUBY_VM_SET_TIMER_INTERRUPT(running);

if ((volatile rb_thread_t*)vm->running_thread == running)
break;

clear_timer_interrupt(running);
}


/* check signal */
rb_threadptr_check_signal(vm->main_thread);

Expand Down