After do_mutex_lock(mutex), the mutex should be owned by the current
thread. Adding an assertion for this assumption.
This commit is contained in:
Koichi Sasada 2019-10-28 12:19:18 +09:00
Родитель 85d966af21
Коммит d8d581bfc4
1 изменённых файлов: 16 добавлений и 5 удалений

Просмотреть файл

@ -223,6 +223,17 @@ rb_mutex_trylock(VALUE self)
*/
static const rb_thread_t *patrol_thread = NULL;
static VALUE
mutex_owned_p(rb_thread_t *th, rb_mutex_t *mutex)
{
if (mutex->th == th) {
return Qtrue;
}
else {
return Qfalse;
}
}
static VALUE
do_mutex_lock(VALUE self, int interruptible_p)
{
@ -298,6 +309,10 @@ do_mutex_lock(VALUE self, int interruptible_p)
}
}
}
// assertion
if (mutex_owned_p(th, mutex) == Qfalse) rb_bug("do_mutex_lock: mutex is not owned.");
return self;
}
@ -329,14 +344,10 @@ rb_mutex_lock(VALUE self)
VALUE
rb_mutex_owned_p(VALUE self)
{
VALUE owned = Qfalse;
rb_thread_t *th = GET_THREAD();
rb_mutex_t *mutex = mutex_ptr(self);
if (mutex->th == th)
owned = Qtrue;
return owned;
return mutex_owned_p(th, mutex);
}
static const char *