ruby-changes:58467
From: Koichi <ko1@a...>
Date: Mon, 28 Oct 2019 12:20:37 +0900 (JST)
Subject: [ruby-changes:58467] d8d581bfc4 (master): add assertion for mutex_lock.
https://git.ruby-lang.org/ruby.git/commit/?id=d8d581bfc4 From d8d581bfc4cee87a59e40eac20e51fe199eb44bf Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Mon, 28 Oct 2019 12:19:18 +0900 Subject: 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. diff --git a/thread_sync.c b/thread_sync.c index 492a449..efe295e 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -224,6 +224,17 @@ rb_mutex_trylock(VALUE self) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L224 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) { rb_thread_t *th = GET_THREAD(); @@ -298,6 +309,10 @@ do_mutex_lock(VALUE self, int interruptible_p) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L309 } } } + + // 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) https://github.com/ruby/ruby/blob/trunk/thread_sync.c#L344 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 * -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/