aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
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;
}