aboutsummaryrefslogtreecommitdiffstats
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-08 07:00:13 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-08 07:00:13 +0000
commit73836caa40b1082329b1b93fc7cc373152f9402f (patch)
tree6fd1e0e9fb8eedfa8087c1634f76b1e9312cb258 /process.c
parent4778a63f2da6e95c71be9547718406835df9ed28 (diff)
downloadruby-73836caa40b1082329b1b93fc7cc373152f9402f.tar.gz
process.c: retry loop
* process.c (rb_waitpid): refactor retry loop by interrupt. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51792 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/process.c b/process.c
index 8081ce86f1..d3a1596d14 100644
--- a/process.c
+++ b/process.c
@@ -863,25 +863,28 @@ rb_waitpid_blocking(void *data)
return (void *)(VALUE)result;
}
-rb_pid_t
-rb_waitpid(rb_pid_t pid, int *st, int flags)
+static rb_pid_t
+do_waitpid_nonblocking(rb_pid_t pid, int *st, int flags)
{
- rb_pid_t result;
+ void *result;
struct waitpid_arg arg;
-
- retry:
arg.pid = pid;
arg.st = st;
arg.flags = flags;
- result = (rb_pid_t)(VALUE)rb_thread_call_without_gvl(rb_waitpid_blocking, &arg,
- RUBY_UBF_PROCESS, 0);
- if (result < 0) {
- if (errno == EINTR) {
- rb_thread_t *th = GET_THREAD();
- RUBY_VM_CHECK_INTS(th);
- goto retry;
- }
- return (rb_pid_t)-1;
+ result = rb_thread_call_without_gvl(rb_waitpid_blocking, &arg,
+ RUBY_UBF_PROCESS, 0);
+ return (rb_pid_t)(VALUE)result;
+}
+
+rb_pid_t
+rb_waitpid(rb_pid_t pid, int *st, int flags)
+{
+ rb_pid_t result;
+
+ while ((result = do_waitpid_nonblocking(pid, st, flags)) < 0 &&
+ (errno == EINTR)) {
+ rb_thread_t *th = GET_THREAD();
+ RUBY_VM_CHECK_INTS(th);
}
if (result > 0) {
rb_last_status_set(*st, result);