mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
edb5c67195
commit
f7ccb8dd88
Notes:
git
2020-09-15 00:05:42 +09:00
3 changed files with 16 additions and 1 deletions
10
ractor.c
10
ractor.c
|
@ -877,6 +877,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield
|
||||||
VALUE crv = cr->self;
|
VALUE crv = cr->self;
|
||||||
VALUE ret = Qundef;
|
VALUE ret = Qundef;
|
||||||
int i;
|
int i;
|
||||||
|
bool interrupted = false;
|
||||||
enum ractor_wait_status wait_status = 0;
|
enum ractor_wait_status wait_status = 0;
|
||||||
bool yield_p = (yielded_value != Qundef) ? true : false;
|
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;
|
rs = NULL;
|
||||||
|
|
||||||
|
restart:
|
||||||
|
|
||||||
if (yield_p) {
|
if (yield_p) {
|
||||||
actions[i].type = ractor_select_action_yield;
|
actions[i].type = ractor_select_action_yield;
|
||||||
actions[i].v = Qundef;
|
actions[i].v = Qundef;
|
||||||
|
@ -1079,6 +1082,7 @@ ractor_select(rb_execution_context_t *ec, const VALUE *rs, int alen, VALUE yield
|
||||||
break;
|
break;
|
||||||
case wakeup_by_interrupt:
|
case wakeup_by_interrupt:
|
||||||
ret = Qundef;
|
ret = Qundef;
|
||||||
|
interrupted = true;
|
||||||
goto cleanup;
|
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.taken_basket.type == basket_type_none);
|
||||||
VM_ASSERT(cr->wait.yielded_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);
|
VM_ASSERT(ret != Qundef);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
6
thread.c
6
thread.c
|
@ -218,6 +218,12 @@ vm_check_ints_blocking(rb_execution_context_t *ec)
|
||||||
return rb_threadptr_execute_interrupts(th, 1);
|
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
|
* 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()
|
* 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_execution_context_mark(const rb_execution_context_t *ec);
|
||||||
void rb_fiber_close(rb_fiber_t *fib);
|
void rb_fiber_close(rb_fiber_t *fib);
|
||||||
void Init_native_thread(rb_thread_t *th);
|
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)
|
#define RUBY_VM_CHECK_INTS(ec) rb_vm_check_ints(ec)
|
||||||
static inline void
|
static inline void
|
||||||
|
|
Loading…
Reference in a new issue