summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/thread.c b/thread.c
index 4f713a2cc9..57b2085735 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;
}