diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-09 05:43:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-04-09 05:43:29 +0000 |
commit | 69352c0d4d98a16f82ae388297ecfff940747ae2 (patch) | |
tree | 8dd66363f68e375c821cec96006411e947e35762 /thread.c | |
parent | 5098d7ae0dcef98c82e64280d2aded2676738c3b (diff) | |
download | ruby-69352c0d4d98a16f82ae388297ecfff940747ae2.tar.gz |
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@15931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 31 |
1 files changed, 10 insertions, 21 deletions
@@ -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; } |