ruby-changes:62944
From: Koichi <ko1@a...>
Date: Tue, 15 Sep 2020 00:05:30 +0900 (JST)
Subject: [ruby-changes:62944] f7ccb8dd88 (master): restart Ractor.select on intterupt
https://git.ruby-lang.org/ruby.git/commit/?id=f7ccb8dd88 From f7ccb8dd88c52b2294742c3abb87098ee4076799 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Mon, 14 Sep 2020 10:30:22 +0900 Subject: restart Ractor.select on intterupt signal can interrupt Ractor.select, but if there is no exception, Ractor.select should restart automatically. diff --git a/ractor.c b/ractor.c index 18263d2..0ad1373 100644 --- a/ractor.c +++ b/ractor.c @@ -877,6 +877,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield https://github.com/ruby/ruby/blob/trunk/ractor.c#L877 VALUE crv = cr->self; VALUE ret = Qundef; int i; + bool interrupted = false; enum ractor_wait_status wait_status = 0; bool yield_p = (yielded_value != Qundef) ? true : false; @@ -914,6 +915,8 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield https://github.com/ruby/ruby/blob/trunk/ractor.c#L915 } rs = NULL; + restart: + if (yield_p) { actions[i].type = ractor_select_action_yield; actions[i].v = Qundef; @@ -1079,6 +1082,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield https://github.com/ruby/ruby/blob/trunk/ractor.c#L1082 break; case wakeup_by_interrupt: ret = Qundef; + interrupted = true; goto cleanup; } } @@ -1095,7 +1099,11 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield https://github.com/ruby/ruby/blob/trunk/ractor.c#L1099 VM_ASSERT(cr->wait.taken_basket.type == basket_type_none); VM_ASSERT(cr->wait.yielded_basket.type == basket_type_none); - RUBY_VM_CHECK_INTS(ec); + if (interrupted) { + rb_vm_check_ints_blocking(ec); + interrupted = false; + goto restart; + } VM_ASSERT(ret != Qundef); return ret; diff --git a/thread.c b/thread.c index ab574e5..6b20716 100644 --- a/thread.c +++ b/thread.c @@ -218,6 +218,12 @@ vm_check_ints_blocking(rb_execution_context_t *ec) https://github.com/ruby/ruby/blob/trunk/thread.c#L218 return rb_threadptr_execute_interrupts(th, 1); } +int +rb_vm_check_ints_blocking(rb_execution_context_t *ec) +{ + return vm_check_ints_blocking(ec); +} + /* * poll() is supported by many OSes, but so far Linux is the only * one we know of that supports using poll() in all places select() diff --git a/vm_core.h b/vm_core.h index 7071442..1d86961 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1836,6 +1836,7 @@ void rb_execution_context_update(const rb_execution_context_t *ec); https://github.com/ruby/ruby/blob/trunk/vm_core.h#L1836 void rb_execution_context_mark(const rb_execution_context_t *ec); void rb_fiber_close(rb_fiber_t *fib); void Init_native_thread(rb_thread_t *th); +int rb_vm_check_ints_blocking(rb_execution_context_t *ec); #define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec) static inline void -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/