From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.8 required=3.0 tests=ALL_TRUSTED,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS shortcircuit=no autolearn=no autolearn_force=no version=3.4.1 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E8E991F62E; Mon, 25 Jun 2018 23:50:57 +0000 (UTC) From: Eric Wong To: spew@80x24.org Cc: Eric Wong Subject: [PATCH 3/8] mjit.c: allow working on platforms without SIGCHLD Date: Mon, 25 Jun 2018 23:50:46 +0000 Message-Id: <20180625235051.66045-4-e@80x24.org> In-Reply-To: <20180625235051.66045-1-e@80x24.org> References: <20180625235051.66045-1-e@80x24.org> List-Id: While we're at it, simplify lock management in exec_process by avoiding early returns. --- mjit.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/mjit.c b/mjit.c index 63cd35da21..659461cea6 100644 --- a/mjit.c +++ b/mjit.c @@ -137,6 +137,7 @@ pid_t ruby_waitpid_locked(rb_vm_t *, rb_pid_t, int *status, int options, #define WEXITSTATUS(S) (S) #define WIFSIGNALED(S) (0) typedef intptr_t pid_t; +#define USE_RUBY_WAITPID_LOCKED (0) #endif /* Atomically set function pointer if possible. */ @@ -150,6 +151,10 @@ typedef intptr_t pid_t; # define MJIT_ATOMIC_SET(var, val) ATOMIC_SET(var, val) #endif +#ifndef USE_RUBY_WAITPID_LOCKED /* platforms with real waitpid */ +# define USE_RUBY_WAITPID_LOCKED (1) +#endif /* USE_RUBY_WAITPID_LOCKED */ + /* A copy of MJIT portion of MRI options since MJIT initialization. We need them as MJIT threads still can work when the most MRI data were freed. */ @@ -406,24 +411,23 @@ start_process(const char *path, char *const *argv) static int exec_process(const char *path, char *const argv[]) { - int stat, exit_code; + int stat, exit_code = -2; pid_t pid; - rb_vm_t *vm = GET_VM(); + rb_vm_t *vm = USE_RUBY_WAITPID_LOCKED ? GET_VM() : 0; rb_nativethread_cond_t cond; - rb_nativethread_lock_lock(&vm->waitpid_lock); - pid = start_process(path, argv); - if (pid <= 0) { - rb_nativethread_lock_unlock(&vm->waitpid_lock); - return -2; + if (vm) { + rb_native_cond_initialize(&cond); + rb_nativethread_lock_lock(&vm->waitpid_lock); } - rb_native_cond_initialize(&cond); - for (;;) { - pid_t r = ruby_waitpid_locked(vm, pid, &stat, 0, &cond); + + pid = start_process(path, argv); + for (;pid > 0;) { + pid_t r = vm ? ruby_waitpid_locked(vm, pid, &stat, 0, &cond) + : waitpid(pid, &stat, 0); if (r == -1) { if (errno == EINTR) continue; /* should never happen */ fprintf(stderr, "waitpid: %s\n", strerror(errno)); - exit_code = -2; break; } else if (r == pid) { @@ -436,8 +440,11 @@ exec_process(const char *path, char *const argv[]) } } } - rb_nativethread_lock_unlock(&vm->waitpid_lock); - rb_native_cond_destroy(&cond); + + if (vm) { + rb_native_cond_destroy(&cond); + rb_nativethread_lock_unlock(&vm->waitpid_lock); + } return exit_code; } -- EW