Skip to content

Commit

Permalink
* thread.c (lock_func): optimized and checks for interrupt_flag.
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
nobu committed Apr 9, 2008
1 parent 5098d7a commit 69352c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
11 changes: 7 additions & 4 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Wed Apr 9 14:43:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* 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].

Wed Apr 9 12:12:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* test/ruby/test_thread.rb: new tests from Sylvain Joyeux in
[ruby-Patches-19361].

Tue Apr 8 21:38:55 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* thread.c (lock_func): optimized. based on a patch from Sylvain
Joyeux in [ruby-Patches-19362].
Tue Apr 8 21:36:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>

* thread.c (rb_mutex_sleep): ensures to re-acquire at waking up.
[ruby-Patches-19361]
Expand Down
31 changes: 10 additions & 21 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 69352c0

Please sign in to comment.