зеркало из https://github.com/github/ruby.git
add assertion for mutex_lock.
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:
Родитель
85d966af21
Коммит
d8d581bfc4
|
@ -223,6 +223,17 @@ rb_mutex_trylock(VALUE self)
|
||||||
*/
|
*/
|
||||||
static const rb_thread_t *patrol_thread = NULL;
|
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
|
static VALUE
|
||||||
do_mutex_lock(VALUE self, int interruptible_p)
|
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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,14 +344,10 @@ rb_mutex_lock(VALUE self)
|
||||||
VALUE
|
VALUE
|
||||||
rb_mutex_owned_p(VALUE self)
|
rb_mutex_owned_p(VALUE self)
|
||||||
{
|
{
|
||||||
VALUE owned = Qfalse;
|
|
||||||
rb_thread_t *th = GET_THREAD();
|
rb_thread_t *th = GET_THREAD();
|
||||||
rb_mutex_t *mutex = mutex_ptr(self);
|
rb_mutex_t *mutex = mutex_ptr(self);
|
||||||
|
|
||||||
if (mutex->th == th)
|
return mutex_owned_p(th, mutex);
|
||||||
owned = Qtrue;
|
|
||||||
|
|
||||||
return owned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
|
Загрузка…
Ссылка в новой задаче