Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed patch for [Bug #4911] #182

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
Fri Sep 14 17:30:14 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>

* 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 <usa@ruby-lang.org>

* enc/depend: fixed wrong change in a part of r34802.
Expand Down
29 changes: 26 additions & 3 deletions thread.c
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