restart Ractor.select on intterupt

signal can interrupt Ractor.select, but if there is no exception,
Ractor.select should restart automatically.
This commit is contained in:
Koichi Sasada 2020-09-14 10:30:22 +09:00
Родитель edb5c67195
Коммит f7ccb8dd88
3 изменённых файлов: 16 добавлений и 1 удалений

Просмотреть файл

@ -877,6 +877,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield
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
}
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
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
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;

Просмотреть файл

@ -218,6 +218,12 @@ vm_check_ints_blocking(rb_execution_context_t *ec)
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()

Просмотреть файл

@ -1836,6 +1836,7 @@ void rb_execution_context_update(const rb_execution_context_t *ec);
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