summaryrefslogtreecommitdiff
path: root/ext/monitor
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2019-11-12 10:02:47 +0900
committerKoichi Sasada <ko1@atdot.net>2019-11-12 10:07:45 +0900
commitfd6445b7e8bab9d340be6f76688a8b96f1b52029 (patch)
treef68a2f6702d897e7fb64a04ea2e9e68b43031a53 /ext/monitor
parentfef4370b409c990228cded2c425a6afb3bec2906 (diff)
Monitor#exit: check monitor ownership.
Monitor#exit should be called by only onwer Thread. However, there is not check for it.
Diffstat (limited to 'ext/monitor')
-rw-r--r--ext/monitor/monitor.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/ext/monitor/monitor.c b/ext/monitor/monitor.c
index 2d399768b2..256fc4d7db 100644
--- a/ext/monitor/monitor.c
+++ b/ext/monitor/monitor.c
@@ -86,10 +86,25 @@ monitor_enter(VALUE monitor)
}
static VALUE
+monitor_check_owner(VALUE monitor)
+{
+ struct rb_monitor *mc = monitor_ptr(monitor);
+ if (!mc_owner_p(mc)) {
+ rb_raise(rb_eThreadError, "current thread not owner");
+ }
+ return Qnil;
+}
+
+static VALUE
monitor_exit(VALUE monitor)
{
+ monitor_check_owner(monitor);
+
struct rb_monitor *mc = monitor_ptr(monitor);
+
+ if (mc->count <= 0) rb_bug("monitor_exit: count:%d\n", (int)mc->count);
mc->count--;
+
if (mc->count == 0) {
RB_OBJ_WRITE(monitor, &mc->owner, Qnil);
rb_mutex_unlock(mc->mutex);
@@ -112,16 +127,6 @@ monitor_owned_p(VALUE monitor)
}
static VALUE
-monitor_check_owner(VALUE monitor)
-{
- struct rb_monitor *mc = monitor_ptr(monitor);
- if (!mc_owner_p(mc)) {
- rb_raise(rb_eThreadError, "current thread not owner");
- }
- return Qnil;
-}
-
-static VALUE
monitor_exit_for_cond(VALUE monitor)
{
struct rb_monitor *mc = monitor_ptr(monitor);