1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Short-circuit Process._fork

This commit is contained in:
Nobuyoshi Nakada 2022-07-14 17:39:03 +09:00
parent 844a0edbae
commit b2205cd45c
Notes: git 2022-08-12 16:58:29 +09:00

View file

@ -4328,12 +4328,30 @@ rb_fork_ruby(int *status)
return pid;
}
static rb_pid_t
proc_fork_pid(void)
{
rb_pid_t pid = rb_fork_ruby(NULL);
if (pid == -1) {
rb_sys_fail("fork(2)");
}
return pid;
}
rb_pid_t
rb_call_proc__fork(void)
{
VALUE pid = rb_funcall(rb_mProcess, rb_intern("_fork"), 0);
return NUM2PIDT(pid);
ID id__fork;
CONST_ID(id__fork, "_fork");
if (rb_method_basic_definition_p(CLASS_OF(rb_mProcess), id__fork)) {
return proc_fork_pid();
}
else {
VALUE pid = rb_funcall(rb_mProcess, id__fork, 0);
return NUM2PIDT(pid);
}
}
#endif
@ -4360,12 +4378,7 @@ rb_call_proc__fork(void)
VALUE
rb_proc__fork(VALUE _obj)
{
rb_pid_t pid = rb_fork_ruby(NULL);
if (pid == -1) {
rb_sys_fail("fork(2)");
}
rb_pid_t pid = proc_fork_pid();
return PIDT2NUM(pid);
}