[前][次][番号順一覧][スレッド一覧]

ruby-changes:73415

From: Takashi <ko1@a...>
Date: Mon, 5 Sep 2022 10:22:56 +0900 (JST)
Subject: [ruby-changes:73415] f6d569b7c0 (master): Call appropriate hooks on MJIT's fork

https://git.ruby-lang.org/ruby.git/commit/?id=f6d569b7c0

From f6d569b7c0ae7cb5e08534330cdf94572a12e869 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Sun, 4 Sep 2022 18:21:56 -0700
Subject: Call appropriate hooks on MJIT's fork

This takes care of signal_self_pipe and other things.
---
 mjit.c    | 22 ++++------------------
 process.c | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/mjit.c b/mjit.c
index 662ef99b32..0aa6d6e7cf 100644
--- a/mjit.c
+++ b/mjit.c
@@ -742,23 +742,17 @@ mjit_compact_unit(struct rb_mjit_unit *unit) https://github.com/ruby/ruby/blob/trunk/mjit.c#L742
     return 1;
 }
 
+extern pid_t rb_mjit_fork();
+
 static pid_t
 start_mjit_compact(struct rb_mjit_unit *unit)
 {
-    rb_vm_t *vm = GET_VM();
-    rb_native_mutex_lock(&vm->waitpid_lock);
-
-    pid_t pid = rb_fork();
+    pid_t pid = rb_mjit_fork();
     if (pid == 0) {
-        rb_native_mutex_unlock(&vm->waitpid_lock);
-
         int exit_code = mjit_compact_unit(unit);
         exit(exit_code);
     }
     else {
-        mjit_add_waiting_pid(vm, pid);
-        rb_native_mutex_unlock(&vm->waitpid_lock);
-
         return pid;
     }
 }
@@ -908,20 +902,12 @@ mjit_compile_unit(struct rb_mjit_unit *unit) https://github.com/ruby/ruby/blob/trunk/mjit.c#L902
 static pid_t
 start_mjit_compile(struct rb_mjit_unit *unit)
 {
-    rb_vm_t *vm = GET_VM();
-    rb_native_mutex_lock(&vm->waitpid_lock);
-
-    pid_t pid = rb_fork();
+    pid_t pid = rb_mjit_fork();
     if (pid == 0) {
-        rb_native_mutex_unlock(&vm->waitpid_lock);
-
         int exit_code = mjit_compile_unit(unit);
         exit(exit_code);
     }
     else {
-        mjit_add_waiting_pid(vm, pid);
-        rb_native_mutex_unlock(&vm->waitpid_lock);
-
         return pid;
     }
 }
diff --git a/process.c b/process.c
index 57df2dc06f..405c7edcb3 100644
--- a/process.c
+++ b/process.c
@@ -4204,6 +4204,29 @@ retry_fork_async_signal_safe(struct rb_process_status *status, int *ep, https://github.com/ruby/ruby/blob/trunk/process.c#L4204
     }
 }
 
+#if USE_MJIT
+// This is used to create MJIT's child Ruby process
+pid_t
+rb_mjit_fork(void)
+{
+    struct child_handler_disabler_state old;
+    rb_vm_t *vm = GET_VM();
+    prefork();
+    disable_child_handler_before_fork(&old);
+    before_fork_ruby();
+
+    rb_native_mutex_lock(&vm->waitpid_lock);
+    pid_t pid = rb_fork();
+    if (pid > 0) mjit_add_waiting_pid(vm, pid);
+    rb_native_mutex_unlock(&vm->waitpid_lock);
+
+    after_fork_ruby();
+    disable_child_handler_fork_parent(&old);
+
+    return pid;
+}
+#endif
+
 static rb_pid_t
 fork_check_err(struct rb_process_status *status, int (*chfunc)(void*, char *, size_t), void *charg,
         VALUE fds, char *errmsg, size_t errmsg_buflen,
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]