summaryrefslogtreecommitdiffstats
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
commit863846421ce1cbeb833a04767cfab65d7d466e9e (patch)
treea887e005315b911b8e15d8d7770b9355f206e3ed /thread.c
parent58918a477de77cab86ac3e7224921f5d1d622956 (diff)
downloadruby-863846421ce1cbeb833a04767cfab65d7d466e9e.tar.gz
ruby-863846421ce1cbeb833a04767cfab65d7d466e9e.tar.xz
ruby-863846421ce1cbeb833a04767cfab65d7d466e9e.zip
* 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: http://svn.ruby-lang.org/repos/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 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;
}