comparison src/event/modules/ngx_rtsig_module.c @ 316:a0beefedaf94

nginx-0.0.3-2004-04-15-00:34:05 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 14 Apr 2004 20:34:05 +0000
parents 6b91bfbc4123
children 1308b98496a2
comparison
equal deleted inserted replaced
315:39b6f2df45c0 316:a0beefedaf94
190 190
191 int ngx_rtsig_process_events(ngx_cycle_t *cycle) 191 int ngx_rtsig_process_events(ngx_cycle_t *cycle)
192 { 192 {
193 int signo; 193 int signo;
194 ngx_int_t instance, i; 194 ngx_int_t instance, i;
195 ngx_uint_t expire;
195 size_t n; 196 size_t n;
196 ngx_msec_t timer; 197 ngx_msec_t timer;
197 ngx_err_t err; 198 ngx_err_t err;
198 siginfo_t si; 199 siginfo_t si;
199 struct timeval tv; 200 struct timeval tv;
200 struct timespec ts, *tp; 201 struct timespec ts, *tp;
201 struct sigaction sa; 202 struct sigaction sa;
203 ngx_epoch_msec_t delta;
202 ngx_connection_t *c; 204 ngx_connection_t *c;
203 ngx_epoch_msec_t delta;
204 ngx_rtsig_conf_t *rtscf; 205 ngx_rtsig_conf_t *rtscf;
205 206
206 timer = ngx_event_find_timer(); 207 for ( ;; ) {
207 ngx_old_elapsed_msec = ngx_elapsed_msec; 208 timer = ngx_event_find_timer();
208 209
209 if (timer) { 210 if (timer != 0) {
211 break;
212 }
213
214 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
215 "rtsig expired timer");
216
217 ngx_event_expire_timers(0);
218 }
219
220 expire = 1;
221
222 if (ngx_accept_mutex) {
223 if (ngx_trylock_accept_mutex(cycle) == NGX_ERROR) {
224 return NGX_ERROR;
225 }
226
227 if (ngx_accept_mutex_held == 0
228 && (timer == NGX_TIMER_INFINITE || timer > ngx_accept_mutex_delay))
229 {
230 timer = ngx_accept_mutex_delay;
231 expire = 0;
232 }
233 }
234
235 if (timer == NGX_TIMER_INFINITE) {
236 tp = NULL;
237 expire = 0;
238
239 } else {
210 ts.tv_sec = timer / 1000; 240 ts.tv_sec = timer / 1000;
211 ts.tv_nsec = (timer % 1000) * 1000000; 241 ts.tv_nsec = (timer % 1000) * 1000000;
212 tp = &ts; 242 tp = &ts;
213 243 }
214 } else { 244
215 tp = NULL; 245 ngx_old_elapsed_msec = ngx_elapsed_msec;
216 }
217 246
218 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 247 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
219 "rtsig timer: %d", timer); 248 "rtsig timer: %d", timer);
220 249
221 /* Linux sigwaitinfo() is sigtimedwait() with the NULL timeout pointer */ 250 /* Linux sigwaitinfo() is sigtimedwait() with the NULL timeout pointer */
235 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec; 264 ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
236 265
237 if (err) { 266 if (err) {
238 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, 267 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
239 cycle->log, err, "sigtimedwait() failed"); 268 cycle->log, err, "sigtimedwait() failed");
240 return NGX_ERROR; 269 ngx_accept_mutex_unlock();
241 } 270 return NGX_ERROR;
242 271 }
243 if (timer) { 272
273 if (timer != NGX_TIMER_INFINITE) {
244 delta = ngx_elapsed_msec - delta; 274 delta = ngx_elapsed_msec - delta;
245 275
246 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0, 276 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
247 "rtsig timer: %d, delta: %d", timer, (int) delta); 277 "rtsig timer: %d, delta: %d", timer, (int) delta);
248 } 278 }
261 /* TODO: stale signals */ 291 /* TODO: stale signals */
262 292
263 if (si.si_band & (POLLIN|POLLHUP|POLLERR)) { 293 if (si.si_band & (POLLIN|POLLHUP|POLLERR)) {
264 if (c->read->active) { 294 if (c->read->active) {
265 c->read->ready = 1; 295 c->read->ready = 1;
266 c->read->event_handler(c->read); 296
297 if (!ngx_threaded && !ngx_accept_mutex_held) {
298 c->read->event_handler(c->read);
299
300 } else if (c->read->accept) {
301 c->read->event_handler(c->read);
302
303 } else {
304 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
305 ngx_accept_mutex_unlock();
306 return NGX_ERROR;
307 }
308
309 ngx_post_event(c->read);
310
311 ngx_mutex_unlock(ngx_posted_events_mutex);
312 }
267 } 313 }
268 } 314 }
269 315
270 if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) { 316 if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) {
271 if (c->write->active) { 317 if (c->write->active) {
272 c->write->ready = 1; 318 c->write->ready = 1;
273 c->write->event_handler(c->write); 319
320 if (!ngx_threaded && !ngx_accept_mutex_held) {
321 c->write->event_handler(c->write);
322
323 } else {
324
325 if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) {
326 ngx_accept_mutex_unlock();
327 return NGX_ERROR;
328 }
329
330 ngx_post_event(c->write);
331
332 ngx_mutex_unlock(ngx_posted_events_mutex);
333 }
274 } 334 }
275 } 335 }
276 336
277 } else if (signo == SIGIO) { 337 } else if (signo == SIGIO) {
338 ngx_accept_mutex_unlock();
339
278 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 340 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
279 "signal queue overflowed: " 341 "signal queue overflowed: "
280 "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band); 342 "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band);
281 343
282 /* TODO: flush all the used RT signals */ 344 /* TODO: flush all the used RT signals */
298 360
299 361
300 } else { 362 } else {
301 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, 363 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
302 "sigtimedwait() returned unexpected signal: %d", signo); 364 "sigtimedwait() returned unexpected signal: %d", signo);
303 return NGX_ERROR; 365 ngx_accept_mutex_unlock();
304 } 366 return NGX_ERROR;
305 367 }
306 if (timer != (ngx_msec_t) -1 && delta) { 368
369
370 ngx_accept_mutex_unlock();
371
372 if (expire && delta) {
307 ngx_event_expire_timers((ngx_msec_t) delta); 373 ngx_event_expire_timers((ngx_msec_t) delta);
374 }
375
376 if (!ngx_threaded) {
377 ngx_event_process_posted(cycle);
308 } 378 }
309 379
310 return NGX_OK; 380 return NGX_OK;
311 } 381 }
312 382