summaryrefslogtreecommitdiff
path: root/process.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-24 09:43:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-02-24 09:43:40 +0000
commitc034fce5cef74af6d1178eba4bec536e1fa70728 (patch)
tree59a30aa12effd3566e8c308012fd90dffc2b08f0 /process.c
parentf425798fdaca165c200091faf976c3cf9a52637d (diff)
* process.c (rb_waitpid_blocking, rb_waitpid): use UBF feature.
* thread_win32.ci (rb_w32_wait_events_blocking): blocking version. * win32/win32.c (waitpid): use rb_w32_wait_events_blocking(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'process.c')
-rw-r--r--process.c50
1 files changed, 35 insertions, 15 deletions
diff --git a/process.c b/process.c
index 7a4cb411cd..98a65b0433 100644
--- a/process.c
+++ b/process.c
@@ -567,37 +567,58 @@ pst_wcoredump(VALUE st)
#if !defined(HAVE_WAITPID) && !defined(HAVE_WAIT4)
#define NO_WAITPID
static st_table *pid_tbl;
+#else
+struct waitpid_arg {
+ rb_pid_t pid;
+ int *st;
+ int flags;
+};
#endif
-rb_pid_t
-rb_waitpid(rb_pid_t pid, int *st, int flags)
+static VALUE
+rb_waitpid_blocking(rb_thread_t *th, void *data)
{
rb_pid_t result;
#ifndef NO_WAITPID
- int oflags = flags;
- if (!rb_thread_alone()) { /* there're other threads to run */
- flags |= WNOHANG;
- }
+ struct waitpid_arg *arg = data;
+#endif
- retry:
TRAP_BEG;
-#ifdef HAVE_WAITPID
- result = waitpid(pid, st, flags);
+#if defined NO_WAITPID
+ result = wait(data);
+#elif defined HAVE_WAITPID
+ result = waitpid(arg->pid, arg->st, arg->flags);
#else /* HAVE_WAIT4 */
- result = wait4(pid, st, flags, NULL);
+ result = wait4(arg->pid, arg->st, arg->flags, NULL);
#endif
TRAP_END;
+ return (VALUE)result;
+}
+
+rb_pid_t
+rb_waitpid(rb_pid_t pid, int *st, int flags)
+{
+ rb_pid_t result;
+#ifndef NO_WAITPID
+ struct waitpid_arg arg;
+
+ arg.pid = pid;
+ arg.st = st;
+ arg.flags = flags;
+ retry:
+ result = (rb_pid_t)rb_thread_blocking_region(rb_waitpid_blocking,
+ &arg, RB_UBF_DFL);
if (result < 0) {
+#if 0
if (errno == EINTR) {
rb_thread_polling();
goto retry;
}
+#endif
return -1;
}
if (result == 0) {
- if (oflags & WNOHANG) return 0;
rb_thread_polling();
- if (rb_thread_alone()) flags = oflags;
goto retry;
}
#else /* NO_WAITPID */
@@ -612,9 +633,8 @@ rb_waitpid(rb_pid_t pid, int *st, int flags)
}
for (;;) {
- TRAP_BEG;
- result = wait(st);
- TRAP_END;
+ result = (rb_pid_t)rb_thread_blocking_region(rb_waitpid_blocking,
+ st, RB_UBF_DFL);
if (result < 0) {
if (errno == EINTR) {
rb_thread_schedule();