summaryrefslogtreecommitdiff
path: root/thread_sync.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-10-28 12:19:18 +0900
committerKoichi Sasada <ko1@atdot.net>2019-10-28 12:19:18 +0900
commitd8d581bfc4cee87a59e40eac20e51fe199eb44bf (patch)
treee281379d78e492094a99afad3e6dd57f2ab9c13d /thread_sync.c
parent85d966af21ce834ddefe13861bcb42abae244d25 (diff)
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.
Diffstat (limited to 'thread_sync.c')
-rw-r--r--thread_sync.c21
1 files changed, 16 insertions, 5 deletions
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)
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)
}
}
}
+
+ // 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 *