mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
f425798fda
commit
c034fce5ce
4 changed files with 53 additions and 20 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.
|
||||
|
|
52
process.c
52
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
|
||||
|
||||
static VALUE
|
||||
rb_waitpid_blocking(rb_thread_t *th, void *data)
|
||||
{
|
||||
rb_pid_t result;
|
||||
#ifndef NO_WAITPID
|
||||
struct waitpid_arg *arg = data;
|
||||
#endif
|
||||
|
||||
TRAP_BEG;
|
||||
#if defined NO_WAITPID
|
||||
result = wait(data);
|
||||
#elif defined HAVE_WAITPID
|
||||
result = waitpid(arg->pid, arg->st, arg->flags);
|
||||
#else /* HAVE_WAIT4 */
|
||||
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
|
||||
int oflags = flags;
|
||||
if (!rb_thread_alone()) { /* there're other threads to run */
|
||||
flags |= WNOHANG;
|
||||
}
|
||||
struct waitpid_arg arg;
|
||||
|
||||
arg.pid = pid;
|
||||
arg.st = st;
|
||||
arg.flags = flags;
|
||||
retry:
|
||||
TRAP_BEG;
|
||||
#ifdef HAVE_WAITPID
|
||||
result = waitpid(pid, st, flags);
|
||||
#else /* HAVE_WAIT4 */
|
||||
result = wait4(pid, st, flags, NULL);
|
||||
#endif
|
||||
TRAP_END;
|
||||
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();
|
||||
|
|
|
@ -109,12 +109,18 @@ w32_wait_events(HANDLE *events, int count, DWORD timeout, rb_thread_t *th)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue