From 863846421ce1cbeb833a04767cfab65d7d466e9e Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 10 Jan 2008 16:12:32 +0000 Subject: * thread.c (rb_mutex_unlock): proper error message for unlocking mutex that is not locked. a patch from Yusuke ENDOH in [ruby-dev:33010]. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index 31679bb9e..e5b79b733 100644 --- a/thread.c +++ b/thread.c @@ -2362,22 +2362,30 @@ VALUE rb_mutex_unlock(VALUE self) { mutex_t *mutex; + char *err = NULL; GetMutexPtr(self, mutex); - if (mutex->th != GET_THREAD()) { - rb_raise(rb_eThreadError, - "Attempt to unlock a mutex which is locked by another thread"); - } - native_mutex_lock(&mutex->lock); - mutex->th = 0; - if (mutex->cond_waiting > 0) { - /* waiting thread */ - native_cond_signal(&mutex->cond); - mutex->cond_waiting--; + + if (mutex->th == 0) { + err = "Attempt to unlock a mutex which is not locked"; } + else if (mutex->th != GET_THREAD()) { + err = "Attempt to unlock a mutex which is locked by another thread"; + } + else { + mutex->th = 0; + if (mutex->cond_waiting > 0) { + /* waiting thread */ + native_cond_signal(&mutex->cond); + mutex->cond_waiting--; + } + } + native_mutex_unlock(&mutex->lock); + if (err) rb_raise(rb_eThreadError, err); + return self; } -- cgit