summaryrefslogtreecommitdiff
path: root/ext/thread
diff options
context:
space:
mode:
Diffstat (limited to 'ext/thread')
-rw-r--r--ext/thread/thread.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index e9dde37a18..d617185a26 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -390,7 +390,7 @@ rb_mutex_try_lock(VALUE self)
*
*/
-static void
+static VALUE
lock_mutex(Mutex *mutex)
{
VALUE current;
@@ -405,6 +405,7 @@ lock_mutex(Mutex *mutex)
mutex->owner = current;
rb_thread_critical = 0;
+ return Qnil;
}
static VALUE
@@ -429,8 +430,13 @@ unlock_mutex_inner(Mutex *mutex)
VALUE waking;
if (!RTEST(mutex->owner)) {
- return Qundef;
+ rb_raise(rb_eThreadError, "not owner");
}
+
+ if (mutex->owner != rb_thread_current()) {
+ rb_raise(rb_eThreadError, "not owner");
+ }
+
mutex->owner = Qnil;
waking = wake_one(&mutex->waiting);
@@ -623,18 +629,12 @@ static void
wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
rb_thread_critical = 1;
- if (!RTEST(mutex->owner)) {
- rb_thread_critical = 0;
- return;
- }
- if (mutex->owner != rb_thread_current()) {
+ if (rb_thread_current() != mutex->owner) {
rb_thread_critical = 0;
- rb_raise(rb_eThreadError, "Not owner");
+ rb_raise(rb_eThreadError, "not owner of the synchronization mutex");
}
- mutex->owner = Qnil;
- wait_list(&condvar->waiting);
-
- lock_mutex(mutex);
+ unlock_mutex_inner(mutex);
+ rb_ensure(wait_list, (VALUE)&condvar->waiting, lock_mutex, (VALUE)mutex);
}
static VALUE