diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-24 09:43:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-02-24 09:43:40 +0000 |
commit | c034fce5cef74af6d1178eba4bec536e1fa70728 (patch) | |
tree | 59a30aa12effd3566e8c308012fd90dffc2b08f0 | |
parent | f425798fdaca165c200091faf976c3cf9a52637d (diff) | |
download | ruby-c034fce5cef74af6d1178eba4bec536e1fa70728.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | process.c | 50 | ||||
-rw-r--r-- | thread_win32.ci | 8 | ||||
-rw-r--r-- | win32/win32.c | 4 |
4 files changed, 52 insertions, 19 deletions
@@ -1,7 +1,9 @@ -Sat Feb 24 18:41:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> +Sat Feb 24 18:43:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * intern.h (rb_thread_blocking_region): add prototype. + * process.c (rb_waitpid_blocking, rb_waitpid): use UBF feature. + * thread.c (rb_thread_debug): added runtime debugging flag. * thread.c (BLOCKING_REGION): restore previous UBF. @@ -12,6 +14,11 @@ Sat Feb 24 18:41:30 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> + ubf_handle() on Win32 + none on cygwin + * thread_win32.ci (rb_w32_wait_events_blocking): blocking version. + + * win32/win32.c (waitpid): use rb_w32_wait_events_blocking(). + + Sat Feb 24 17:45:48 2007 Minero Aoki <aamine@loveruby.net> * parse.y (f_arg, opt_f_block_arg): ripper should export VALUE. @@ -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(); diff --git a/thread_win32.ci b/thread_win32.ci index aa1664a58a..f04fb93968 100644 --- a/thread_win32.ci +++ b/thread_win32.ci @@ -110,11 +110,17 @@ static void ubf_handle(rb_thread_t *th); #define ubf_select ubf_handle int +rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout) +{ + return w32_wait_events(events, num, timeout, GET_THREAD()); +} + +int rb_w32_wait_events(HANDLE *events, int num, DWORD timeout) { int ret; - BLOCKING_REGION(ret = w32_wait_events(events, num, timeout, GET_THREAD()), ubf_handle); + BLOCKING_REGION(ret = rb_w32_wait_events_blocking(events, num, timeout), ubf_handle); return ret; } diff --git a/win32/win32.c b/win32/win32.c index 8ff3d67472..5f9cace342 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -2936,7 +2936,7 @@ waitpid(rb_pid_t pid, int *stat_loc, int options) return -1; } - ret = rb_w32_wait_events(events, count, timeout); + ret = rb_w32_wait_events_blocking(events, count, timeout); if (ret == WAIT_TIMEOUT) return 0; if ((ret -= WAIT_OBJECT_0) == count) { return -1; @@ -2957,7 +2957,7 @@ waitpid(rb_pid_t pid, int *stat_loc, int options) while (!(pid = poll_child_status(child, stat_loc))) { /* wait... */ - if (rb_w32_wait_events(&child->hProcess, 1, timeout) != WAIT_OBJECT_0) { + if (rb_w32_wait_events_blocking(&child->hProcess, 1, timeout) != WAIT_OBJECT_0) { /* still active */ pid = 0; break; |