summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-10 16:12:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-10 16:12:32 +0000
commitd17bcfc802cfc84212f10eaba5e80640e4b108c6 (patch)
treea887e005315b911b8e15d8d7770b9355f206e3ed /thread.c
parent7a360de149dc00dcbed0a19d97c0882423a9b913 (diff)
* 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.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/thread.c b/thread.c
index 31679bb9ed..e5b79b7330 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;
}