From a8f9da079c475877e050c37bd5e4e7e31fd437c9 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 9 Apr 2008 05:43:29 +0000 Subject: * thread.c (lock_func): optimized and checks for interrupt_flag. based on a patch from Sylvain Joyeux in [ruby-Patches-19361] and [ruby-Patches-19362]. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@15931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 4f713a2cc..57b208573 100644 --- a/thread.c +++ b/thread.c @@ -2320,30 +2320,19 @@ rb_mutex_trylock(VALUE self) static VALUE lock_func(rb_thread_t *th, mutex_t *mutex) { - int locked = 0; - - while (locked == 0) { - native_mutex_lock(&mutex->lock); - { - if (mutex->th == 0) { - mutex->th = th; - locked = 1; - } - else { - mutex->cond_waiting++; - native_cond_wait(&mutex->cond, &mutex->lock); + native_mutex_lock(&mutex->lock); + while (mutex->th) { + mutex->cond_waiting++; + native_cond_wait(&mutex->cond, &mutex->lock); - if (th->interrupt_flag) { - locked = 1; - } - else if (mutex->th == 0) { - mutex->th = th; - locked = 1; - } - } + if (th->interrupt_flag) { + native_mutex_unlock(&mutex->lock); + RUBY_VM_CHECK_INTS(); + native_mutex_lock(&mutex->lock); } - native_mutex_unlock(&mutex->lock); } + mutex->th = th; + native_mutex_unlock(&mutex->lock); return Qnil; } -- cgit