diff options
author | Koichi Sasada <[email protected]> | 2019-10-20 15:45:30 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2019-10-20 15:45:30 +0900 |
commit | a236eaa762137d7cb32b8311e0ef9a74bbb0f385 () | |
tree | ccf40c23053f1aef9b8445fd8d3e8e4bd816e7a6 /ext/monitor | |
parent | a0a3c701816c2fe4ab6e940c6cf5638756ceb6dc (diff) |
Native MonitorMixin::ConditionVariable#wait
MonitorMixin::ConditionVariable#wait can be interrupted just after Monitor#exit_for_cond. So implementation in C.
-rw-r--r-- | ext/monitor/lib/monitor.rb | 8 | ||||
-rw-r--r-- | ext/monitor/monitor.c | 57 |
2 files changed, 43 insertions, 22 deletions
@@ -105,13 +105,7 @@ module MonitorMixin # def wait(timeout = nil) @monitor.mon_check_owner - count = @monitor.__send__(:exit_for_cond) - begin - @cond.wait(@monitor.__send__(:mutex_for_cond), timeout) - return true - ensure - @monitor.__send__(:enter_for_cond, count) - end end # @@ -122,15 +122,6 @@ monitor_check_owner(VALUE monitor) } static VALUE -monitor_enter_for_cond(VALUE monitor, VALUE count) -{ - struct rb_monitor *mc = monitor_ptr(monitor); - RB_OBJ_WRITE(monitor, &mc->owner, rb_thread_current()); - mc->count = NUM2LONG(count); - return Qnil; -} - -static VALUE monitor_exit_for_cond(VALUE monitor) { struct rb_monitor *mc = monitor_ptr(monitor); @@ -140,11 +131,49 @@ monitor_exit_for_cond(VALUE monitor) return LONG2NUM(cnt); } static VALUE -monitor_mutex_for_cond(VALUE monitor) { - struct rb_monitor *mc = monitor_ptr(monitor); - return mc->mutex; } static VALUE @@ -183,7 +212,5 @@ Init_monitor(void) rb_define_method(rb_cMonitor, "mon_owned?", monitor_owned_p, 0); /* internal methods for MonitorMixin::ConditionalVariable */ - rb_define_private_method(rb_cMonitor, "enter_for_cond", monitor_enter_for_cond, 1); - rb_define_private_method(rb_cMonitor, "exit_for_cond", monitor_exit_for_cond, 0); - rb_define_private_method(rb_cMonitor, "mutex_for_cond", monitor_mutex_for_cond, 0); } |