Skip to content

Commit

Permalink
Get rid of MJIT's special fork
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 8, 2023
1 parent 43de236 commit b67f07f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 68 deletions.
53 changes: 0 additions & 53 deletions process.c
Expand Up @@ -1079,29 +1079,13 @@ void rb_sigwait_sleep(const rb_thread_t *, int fd, const rb_hrtime_t *);
void rb_sigwait_fd_put(const rb_thread_t *, int fd);
void rb_thread_sleep_interruptible(void);

#if USE_RJIT
static struct waitpid_state rjit_waitpid_state;

// variables shared with thread.c
// TODO: implement the same thing with postponed_job and obviate these variables
bool rjit_waitpid_finished = false;
int rjit_waitpid_status = 0;
#endif

static int
waitpid_signal(struct waitpid_state *w)
{
if (w->ec) { /* rb_waitpid */
rb_threadptr_interrupt(rb_ec_thread_ptr(w->ec));
return TRUE;
}
#if USE_RJIT
else if (w == &rjit_waitpid_state && w->ret) { /* rjit_add_waiting_pid */
rjit_waitpid_finished = true;
rjit_waitpid_status = w->status;
return TRUE;
}
#endif
return FALSE;
}

Expand Down Expand Up @@ -1197,19 +1181,6 @@ waitpid_state_init(struct waitpid_state *w, rb_pid_t pid, int options)
w->status = 0;
}

#if USE_RJIT
/*
* must be called with vm->waitpid_lock held, this is not interruptible
*/
void
rjit_add_waiting_pid(rb_vm_t *vm, rb_pid_t pid)
{
waitpid_state_init(&rjit_waitpid_state, pid, 0);
rjit_waitpid_state.ec = 0; // switch the behavior of waitpid_signal
ccan_list_add(&vm->waiting_pids, &rjit_waitpid_state.wnode);
}
#endif

static VALUE
waitpid_sleep(VALUE x)
{
Expand Down Expand Up @@ -4187,30 +4158,6 @@ retry_fork_async_signal_safe(struct rb_process_status *status, int *ep,
}
}

#if USE_RJIT
// This is used to create RJIT's child Ruby process
pid_t
rb_rjit_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) rjit_add_waiting_pid(vm, pid);
rb_native_mutex_unlock(&vm->waitpid_lock);

after_fork_ruby();
disable_child_handler_fork_parent(&old);
if (pid == 0) rb_thread_atfork();

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,
Expand Down
15 changes: 0 additions & 15 deletions thread.c
Expand Up @@ -2280,12 +2280,6 @@ threadptr_get_interrupts(rb_thread_t *th)
return interrupt & (rb_atomic_t)~ec->interrupt_mask;
}

#if USE_RJIT
// process.c
extern bool rjit_waitpid_finished;
extern int rjit_waitpid_status;
#endif

int
rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
{
Expand Down Expand Up @@ -2335,15 +2329,6 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
th->status = prev_status;
}

#if USE_RJIT
// Handle waitpid_signal for RJIT issued by ruby_sigchld_handler. This needs to be done
// outside ruby_sigchld_handler to avoid recursively relying on the SIGCHLD handler.
if (rjit_waitpid_finished && th == th->vm->ractor.main_thread) {
rjit_waitpid_finished = false;
rjit_notify_waitpid(WIFEXITED(rjit_waitpid_status) ? WEXITSTATUS(rjit_waitpid_status) : -1);
}
#endif

/* exception from another thread */
if (pending_interrupt && threadptr_pending_interrupt_active_p(th)) {
VALUE err = rb_threadptr_pending_interrupt_deque(th, blocking_timing ? INTERRUPT_ON_BLOCKING : INTERRUPT_NONE);
Expand Down

0 comments on commit b67f07f

Please sign in to comment.