@@ -66,10 +66,10 @@ get_ppid()
66
66
67
67
VALUE last_status = Qnil ;
68
68
69
- #if !defined(HAVE_WAITPID ) && !defined(HAVE_WAIT4 )
70
- static st_table * pid_tbl ;
71
- #else
69
+ #if defined(HAVE_WAITPID ) || defined(HAVE_WAIT4 )
72
70
# define WAIT_CALL
71
+ #else
72
+ static st_table * pid_tbl ;
73
73
#endif
74
74
75
75
static int
@@ -79,16 +79,20 @@ rb_waitpid(pid, flags, st)
79
79
int * st ;
80
80
{
81
81
int result ;
82
- #if defined(THREAD ) && (defined(HAVE_WAITPID ) || defined(HAVE_WAIT4 ))
82
+ #ifdef WAIT_CALL
83
+ #if defined(THREAD )
83
84
int oflags = flags ;
84
85
if (!thread_alone ()) { /* there're other threads to run */
85
86
flags |= WNOHANG ;
86
87
}
87
88
#endif
88
89
89
- #ifdef HAVE_WAITPID
90
90
retry :
91
+ #ifdef HAVE_WAITPID
91
92
result = waitpid (pid , st , flags );
93
+ #else /* HAVE_WAIT4 */
94
+ result = wait4 (pid , st , flags , NULL );
95
+ #endif
92
96
if (result < 0 ) {
93
97
if (errno == EINTR ) {
94
98
#ifdef THREAD
@@ -106,26 +110,7 @@ rb_waitpid(pid, flags, st)
106
110
goto retry ;
107
111
}
108
112
#endif
109
- #else
110
- #ifdef HAVE_WAIT4
111
- retry :
112
-
113
- result = wait4 (pid , st , flags , NULL );
114
- if (result < 0 ) {
115
- if (errno == EINTR ) {
116
- goto retry ;
117
- }
118
- return -1 ;
119
- }
120
- #ifdef THREAD
121
- if (result == 0 ) {
122
- if (oflags & WNOHANG ) return 0 ;
123
- thread_schedule ();
124
- if (thread_alone ()) flags = oflags ;
125
- goto retry ;
126
- }
127
- #endif
128
- #else
113
+ #else /* WAIT_CALL */
129
114
if (pid_tbl && st_lookup (pid_tbl , pid , st )) {
130
115
last_status = INT2FIX (* st );
131
116
st_delete (pid_tbl , & pid , NULL );
@@ -153,8 +138,10 @@ rb_waitpid(pid, flags, st)
153
138
if (!pid_tbl )
154
139
pid_tbl = st_init_numtable ();
155
140
st_insert (pid_tbl , pid , st );
156
- }
141
+ #ifdef THREAD
142
+ if (!thread_alone ()) thread_schedule ();
157
143
#endif
144
+ }
158
145
#endif
159
146
last_status = INT2FIX (* st );
160
147
return result ;
@@ -192,19 +179,21 @@ f_wait()
192
179
last_status = data .status ;
193
180
return INT2FIX (data .pid );
194
181
}
195
- #endif
196
182
197
183
while ((pid = wait (& state )) < 0 ) {
198
- if (errno == EINTR ) {
184
+ if (errno == EINTR ) {
199
185
#ifdef THREAD
200
- thread_schedule ();
186
+ thread_schedule ();
201
187
#endif
202
- continue ;
203
- }
204
- if (errno == ECHILD ) return Qnil ;
205
- rb_sys_fail (0 );
188
+ continue ;
189
+ }
190
+ rb_sys_fail (0 );
206
191
}
207
192
last_status = INT2FIX (state );
193
+ #else
194
+ if ((pid = rb_waitpid (-1 , 0 , & state )) < 0 )
195
+ rb_sys_fail (0 );
196
+ #endif
208
197
return INT2FIX (pid );
209
198
}
210
199
0 commit comments