diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-10 16:12:32 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-10 16:12:32 +0000 |
commit | d17bcfc802cfc84212f10eaba5e80640e4b108c6 (patch) | |
tree | a887e005315b911b8e15d8d7770b9355f206e3ed /thread.c | |
parent | 7a360de149dc00dcbed0a19d97c0882423a9b913 (diff) | |
download | ruby-d17bcfc802cfc84212f10eaba5e80640e4b108c6.tar.gz |
* thread.c (rb_mutex_unlock): proper error message for unlocking
mutex that is not locked. a patch from Yusuke ENDOH
<mame at tsg.ne.jp> in [ruby-dev:33010].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14980 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -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; } |