mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 08:33:58 +02:00
thread.c (call_without_gvl): spawn thread for UBF iff single-threaded
We need another native thread to call some unblocking functions which aren't RUBY_UBF_IO or RUBY_UBF_PROCESS. Instead of a permanent thread in <= 2.5, we can now rely on the thread cache feature to perform interrupts. [ruby-core:90865] [Bug #15499] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
79aef1272e
commit
9e66910b3b
3 changed files with 33 additions and 0 deletions
8
thread.c
8
thread.c
|
@ -1429,11 +1429,15 @@ call_without_gvl(void *(*func)(void *), void *data1,
|
|||
rb_execution_context_t *ec = GET_EC();
|
||||
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
||||
int saved_errno = 0;
|
||||
VALUE ubf_th = Qfalse;
|
||||
|
||||
if (ubf == RUBY_UBF_IO || ubf == RUBY_UBF_PROCESS) {
|
||||
ubf = ubf_select;
|
||||
data2 = th;
|
||||
}
|
||||
else if (ubf && vm_living_thread_num(th->vm) == 1) {
|
||||
ubf_th = rb_thread_start_unblock_thread();
|
||||
}
|
||||
|
||||
BLOCKING_REGION(th, {
|
||||
val = func(data1);
|
||||
|
@ -1444,6 +1448,10 @@ call_without_gvl(void *(*func)(void *), void *data1,
|
|||
RUBY_VM_CHECK_INTS_BLOCKING(ec);
|
||||
}
|
||||
|
||||
if (ubf_th != Qfalse) {
|
||||
thread_value(rb_thread_kill(ubf_th));
|
||||
}
|
||||
|
||||
errno = saved_errno;
|
||||
|
||||
return val;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue