From c6454ad0ea085f4f56a2994b1d67f1d0e9320609 Mon Sep 17 00:00:00 2001 From: KOSAKI Motohiro Date: Tue, 17 May 2011 22:36:01 +0900 Subject: [PATCH] remove transition_for_lock Signed-off-by: KOSAKI Motohiro --- thread.c | 25 ++++++++++--------------- vm_core.h | 1 - 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/thread.c b/thread.c index 8304396..8f102d9 100644 --- a/thread.c +++ b/thread.c @@ -3426,8 +3426,7 @@ lock_func(rb_thread_t *th, mutex_t *mutex, int timeout_ms) { int interrupted = 0; int err = 0; - native_mutex_lock(&mutex->lock); - th->transition_for_lock = 0; + mutex->cond_waiting++; for (;;) { @@ -3459,9 +3458,6 @@ lock_func(rb_thread_t *th, mutex_t *mutex, int timeout_ms) } } mutex->cond_waiting--; - th->transition_for_lock = 1; - native_mutex_unlock(&mutex->lock); - return interrupted; } @@ -3503,24 +3499,23 @@ rb_mutex_lock(VALUE self) set_unblock_function(th, lock_interrupt, mutex, &oldubf); th->status = THREAD_STOPPED_FOREVER; - th->vm->sleeper++; th->locking_mutex = self; + native_mutex_lock(&mutex->lock); + th->vm->sleeper++; /* - * Carefully! while some contended threads are in lock_fun(), + * Carefully! while some contended threads are in lock_func(), * vm->sleepr is unstable value. we have to avoid both deadlock * and busy loop. */ if (vm_living_thread_num(th->vm) == th->vm->sleeper) { timeout_ms = 100; } + GVL_UNLOCK_BEGIN(); + interrupted = lock_func(th, mutex, timeout_ms); + native_mutex_unlock(&mutex->lock); + GVL_UNLOCK_END(); - th->transition_for_lock = 1; - BLOCKING_REGION_CORE({ - interrupted = lock_func(th, mutex, timeout_ms); - }); - th->transition_for_lock = 0; - remove_signal_thread_list(th); reset_unblock_function(th, &oldubf); th->locking_mutex = Qfalse; @@ -4694,7 +4689,7 @@ check_deadlock_i(st_data_t key, st_data_t val, int *found) rb_thread_t *th; GetThreadPtr(thval, th); - if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th) || th->transition_for_lock) { + if (th->status != THREAD_STOPPED_FOREVER || RUBY_VM_INTERRUPTED(th)) { *found = 1; } else if (th->locking_mutex) { @@ -4719,7 +4714,7 @@ debug_i(st_data_t key, st_data_t val, int *found) rb_thread_t *th; GetThreadPtr(thval, th); - printf("th:%p %d %d %d", th, th->status, th->interrupt_flag, th->transition_for_lock); + printf("th:%p %d %d", th, th->status, th->interrupt_flag); if (th->locking_mutex) { mutex_t *mutex; GetMutexPtr(th->locking_mutex, mutex); diff --git a/vm_core.h b/vm_core.h index c5417d9..1202211 100644 --- a/vm_core.h +++ b/vm_core.h @@ -435,7 +435,6 @@ typedef struct rb_thread_struct { struct rb_unblock_callback unblock; VALUE locking_mutex; struct rb_mutex_struct *keeping_mutexes; - int transition_for_lock; struct rb_vm_tag *tag; struct rb_vm_protect_tag *protect_tag; -- 1.7.4