Mercurial > hg > nginx-vendor-0-6
comparison src/os/unix/ngx_freebsd_rfork_thread.c @ 10:46833bd150cb NGINX_0_1_5
nginx 0.1.5
*) Bugfix: on Solaris and Linux there may be too many "recvmsg()
returned not enough data" alerts.
*) Bugfix: there were the "writev() failed (22: Invalid argument)"
errors on Solaris in proxy mode without sendfile. On other platforms
that do not support sendfile at all the process got caught in an
endless loop.
*) Bugfix: segmentation fault on Solaris in proxy mode and using
sendfile.
*) Bugfix: segmentation fault on Solaris.
*) Bugfix: on-line upgrade did not work on Linux.
*) Bugfix: the ngx_http_autoindex_module module did not escape the
spaces, the quotes, and the percent signs in the directory listing.
*) Change: the decrease of the copy operations.
*) Feature: the userid_p3p directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 11 Nov 2004 00:00:00 +0300 |
parents | f0b350454894 |
children | 6f8b0dc0f8dd |
comparison
equal
deleted
inserted
replaced
9:77eee314ddbd | 10:46833bd150cb |
---|---|
19 * spinning in the lock the thread calls sched_yield(). However the light | 19 * spinning in the lock the thread calls sched_yield(). However the light |
20 * mutecies are intended to be used with the "trylock" operation only. | 20 * mutecies are intended to be used with the "trylock" operation only. |
21 * The SysV semop() is a cheap syscall, particularly if it has little sembuf's | 21 * The SysV semop() is a cheap syscall, particularly if it has little sembuf's |
22 * and does not use SEM_UNDO. | 22 * and does not use SEM_UNDO. |
23 * | 23 * |
24 * The condition variable implementation uses signal #64. The signal handler | 24 * The condition variable implementation uses the signal #64. |
25 * is SIG_IGN so the kill() is a cheap syscall. The thread waits a signal | 25 * The signal handler is SIG_IGN so the kill() is a cheap syscall. |
26 * in kevent(). The use of the EVFILT_SIGNAL is safe since FreeBSD 4.7. | 26 * The thread waits a signal in kevent(). The use of the EVFILT_SIGNAL |
27 * is safe since FreeBSD 4.10-STABLE. | |
27 * | 28 * |
28 * This threads implementation currently works on i386 (486+) and amd64 | 29 * This threads implementation currently works on i386 (486+) and amd64 |
29 * platforms only. | 30 * platforms only. |
30 */ | 31 */ |
31 | 32 |
112 } | 113 } |
113 | 114 |
114 #endif | 115 #endif |
115 | 116 |
116 | 117 |
117 int ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, | 118 ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, |
118 ngx_log_t *log) | 119 ngx_log_t *log) |
119 { | 120 { |
120 int id, err; | 121 ngx_pid_t id; |
121 char *stack, *stack_top; | 122 ngx_err_t err; |
123 char *stack, *stack_top; | |
122 | 124 |
123 if (nthreads >= max_threads) { | 125 if (nthreads >= max_threads) { |
124 ngx_log_error(NGX_LOG_CRIT, log, 0, | 126 ngx_log_error(NGX_LOG_CRIT, log, 0, |
125 "no more than %d threads can be created", max_threads); | 127 "no more than %ui threads can be created", max_threads); |
126 return NGX_ERROR; | 128 return NGX_ERROR; |
127 } | 129 } |
128 | 130 |
129 last_stack -= ngx_thread_stack_size; | 131 last_stack -= ngx_thread_stack_size; |
130 | 132 |
131 stack = mmap(last_stack, usable_stack_size, PROT_READ|PROT_WRITE, | 133 stack = mmap(last_stack, usable_stack_size, PROT_READ|PROT_WRITE, |
132 MAP_STACK, -1, 0); | 134 MAP_STACK, -1, 0); |
133 | 135 |
134 if (stack == MAP_FAILED) { | 136 if (stack == MAP_FAILED) { |
135 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, | 137 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
136 "mmap(" PTR_FMT ":" SIZE_T_FMT | 138 "mmap(%p:%uz, MAP_STACK) thread stack failed", |
137 ", MAP_STACK) thread stack failed", | |
138 last_stack, usable_stack_size); | 139 last_stack, usable_stack_size); |
139 return NGX_ERROR; | 140 return NGX_ERROR; |
140 } | 141 } |
141 | 142 |
142 if (stack != last_stack) { | 143 if (stack != last_stack) { |
143 ngx_log_error(NGX_LOG_ALERT, log, 0, "stack address was changed"); | 144 ngx_log_error(NGX_LOG_ALERT, log, 0, |
145 "stack %p address was changed to %p", last_stack, stack); | |
146 return NGX_ERROR; | |
144 } | 147 } |
145 | 148 |
146 stack_top = stack + usable_stack_size; | 149 stack_top = stack + usable_stack_size; |
147 | 150 |
148 ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, | 151 ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, |
149 "thread stack: " PTR_FMT "-" PTR_FMT, stack, stack_top); | 152 "thread stack: %p-%p", stack, stack_top); |
150 | 153 |
151 ngx_set_errno(0); | 154 ngx_set_errno(0); |
152 | 155 |
153 id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top, | 156 id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top, |
154 (ngx_rfork_thread_func_pt) func, arg); | 157 (ngx_rfork_thread_func_pt) func, arg); |
162 *tid = id; | 165 *tid = id; |
163 nthreads = (ngx_freebsd_kern_usrstack - stack_top) | 166 nthreads = (ngx_freebsd_kern_usrstack - stack_top) |
164 / ngx_thread_stack_size; | 167 / ngx_thread_stack_size; |
165 tids[nthreads] = id; | 168 tids[nthreads] = id; |
166 | 169 |
167 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %d", id); | 170 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %P", id); |
168 } | 171 } |
169 | 172 |
170 return err; | 173 return err; |
171 } | 174 } |
172 | 175 |
203 /* the main thread stack red zone */ | 206 /* the main thread stack red zone */ |
204 rz_size = ngx_pagesize; | 207 rz_size = ngx_pagesize; |
205 red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); | 208 red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); |
206 | 209 |
207 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, | 210 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
208 "usrstack: " PTR_FMT " red zone: " PTR_FMT, | 211 "usrstack: %p red zone: %p", |
209 ngx_freebsd_kern_usrstack, red_zone); | 212 ngx_freebsd_kern_usrstack, red_zone); |
210 | 213 |
211 zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); | 214 zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); |
212 if (zone == MAP_FAILED) { | 215 if (zone == MAP_FAILED) { |
213 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 216 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
214 "mmap(" PTR_FMT ":" SIZE_T_FMT | 217 "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed", |
215 ", PROT_NONE, MAP_ANON) red zone failed", | |
216 red_zone, rz_size); | 218 red_zone, rz_size); |
217 return NGX_ERROR; | 219 return NGX_ERROR; |
218 } | 220 } |
219 | 221 |
220 if (zone != red_zone) { | 222 if (zone != red_zone) { |
221 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, | 223 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
222 "red zone address was changed"); | 224 "red zone %p address was changed to %p", red_zone, zone); |
223 } | 225 return NGX_ERROR; |
224 | 226 } |
225 /* create the threads errno's array */ | 227 |
228 /* create the thread errno' array */ | |
226 | 229 |
227 if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) { | 230 if (!(errnos = ngx_calloc(n * sizeof(int), cycle->log))) { |
228 return NGX_ERROR; | 231 return NGX_ERROR; |
229 } | 232 } |
230 | 233 |
231 /* create the threads tids array */ | 234 /* create the thread tids array */ |
232 | 235 |
233 if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) { | 236 if (!(tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log))) { |
234 return NGX_ERROR; | 237 return NGX_ERROR; |
235 } | 238 } |
236 | 239 |
237 tids[0] = ngx_pid; | 240 tids[0] = ngx_pid; |
238 | 241 |
239 /* create the threads tls's array */ | 242 /* create the thread tls' array */ |
240 | 243 |
241 ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *), | 244 ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *), |
242 cycle->log); | 245 cycle->log); |
243 if (ngx_tls == NULL) { | 246 if (ngx_tls == NULL) { |
244 return NGX_ERROR; | 247 return NGX_ERROR; |
272 | 275 |
273 return tids[tid]; | 276 return tids[tid]; |
274 } | 277 } |
275 | 278 |
276 | 279 |
277 ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key) | 280 ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) |
278 { | 281 { |
279 if (nkeys >= NGX_THREAD_KEYS_MAX) { | 282 if (nkeys >= NGX_THREAD_KEYS_MAX) { |
280 return NGX_ENOMEM; | 283 return NGX_ENOMEM; |
281 } | 284 } |
282 | 285 |
284 | 287 |
285 return 0; | 288 return 0; |
286 } | 289 } |
287 | 290 |
288 | 291 |
289 ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) | 292 ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) |
290 { | 293 { |
291 if (key >= NGX_THREAD_KEYS_MAX) { | 294 if (key >= NGX_THREAD_KEYS_MAX) { |
292 return NGX_EINVAL; | 295 return NGX_EINVAL; |
293 } | 296 } |
294 | 297 |
295 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; | 298 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; |
296 return 0; | 299 return 0; |
297 } | 300 } |
298 | 301 |
299 | 302 |
300 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags) | 303 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) |
301 { | 304 { |
302 ngx_mutex_t *m; | 305 ngx_mutex_t *m; |
303 union semun op; | 306 union semun op; |
304 | 307 |
305 if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) { | 308 if (!(m = ngx_alloc(sizeof(ngx_mutex_t), log))) { |
359 } | 362 } |
360 | 363 |
361 #if (NGX_DEBUG) | 364 #if (NGX_DEBUG) |
362 if (try) { | 365 if (try) { |
363 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 366 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
364 "try lock mutex " PTR_FMT " lock:%X", m, m->lock); | 367 "try lock mutex %p lock:%XD", m, m->lock); |
365 } else { | 368 } else { |
366 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 369 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
367 "lock mutex " PTR_FMT " lock:%X", m, m->lock); | 370 "lock mutex %p lock:%XD", m, m->lock); |
368 } | 371 } |
369 #endif | 372 #endif |
370 | 373 |
371 old = m->lock; | 374 old = m->lock; |
372 tries = 0; | 375 tries = 0; |
393 old = m->lock; | 396 old = m->lock; |
394 continue; | 397 continue; |
395 } | 398 } |
396 | 399 |
397 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 400 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
398 "mutex " PTR_FMT " lock:%X", m, m->lock); | 401 "mutex %p lock:%XD", m, m->lock); |
399 | 402 |
400 /* | 403 /* |
401 * The mutex is locked so we increase a number | 404 * The mutex is locked so we increase a number |
402 * of the threads that are waiting on the mutex | 405 * of the threads that are waiting on the mutex |
403 */ | 406 */ |
404 | 407 |
405 lock = old + 1; | 408 lock = old + 1; |
406 | 409 |
407 if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { | 410 if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { |
408 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 411 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
409 "%d threads wait for mutex " PTR_FMT | 412 "%D threads wait for mutex %p, " |
410 ", while only %d threads are available", | 413 "while only %ui threads are available", |
411 lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); | 414 lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); |
412 return NGX_ERROR; | 415 return NGX_ERROR; |
413 } | 416 } |
414 | 417 |
415 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { | 418 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
416 | 419 |
417 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 420 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
418 "wait mutex " PTR_FMT " lock:%X", m, m->lock); | 421 "wait mutex %p lock:%XD", m, m->lock); |
419 | 422 |
420 /* | 423 /* |
421 * The number of the waiting threads has been increased | 424 * The number of the waiting threads has been increased |
422 * and we would wait on the SysV semaphore. | 425 * and we would wait on the SysV semaphore. |
423 * A semaphore should wake up us more efficiently than | 426 * A semaphore should wake up us more efficiently than |
428 op.sem_op = -1; | 431 op.sem_op = -1; |
429 op.sem_flg = 0; | 432 op.sem_flg = 0; |
430 | 433 |
431 if (semop(m->semid, &op, 1) == -1) { | 434 if (semop(m->semid, &op, 1) == -1) { |
432 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 435 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
433 "semop() failed while waiting " | 436 "semop() failed while waiting on mutex %p", m); |
434 "on mutex " PTR_FMT, m); | |
435 return NGX_ERROR; | 437 return NGX_ERROR; |
436 } | 438 } |
437 | 439 |
438 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 440 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
439 "mutex waked up " PTR_FMT " lock:%X", | 441 "mutex waked up %p lock:%XD", m, m->lock); |
440 m, m->lock); | |
441 | 442 |
442 tries = 0; | 443 tries = 0; |
443 old = m->lock; | 444 old = m->lock; |
444 continue; | 445 continue; |
445 } | 446 } |
460 } | 461 } |
461 | 462 |
462 if (tries++ > 1000) { | 463 if (tries++ > 1000) { |
463 | 464 |
464 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 465 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
465 "mutex " PTR_FMT " is contested", m); | 466 "mutex %p is contested", m); |
466 | 467 |
467 /* the mutex is probably contested so we are giving up now */ | 468 /* the mutex is probably contested so we are giving up now */ |
468 | 469 |
469 sched_yield(); | 470 sched_yield(); |
470 | 471 |
472 old = m->lock; | 473 old = m->lock; |
473 } | 474 } |
474 } | 475 } |
475 | 476 |
476 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 477 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
477 "mutex " PTR_FMT " is locked, lock:%X", m, m->lock); | 478 "mutex %p is locked, lock:%XD", m, m->lock); |
478 | 479 |
479 return NGX_OK; | 480 return NGX_OK; |
480 } | 481 } |
481 | 482 |
482 | 483 |
491 | 492 |
492 old = m->lock; | 493 old = m->lock; |
493 | 494 |
494 if (!(old & NGX_MUTEX_LOCK_BUSY)) { | 495 if (!(old & NGX_MUTEX_LOCK_BUSY)) { |
495 ngx_log_error(NGX_LOG_ALERT, m->log, 0, | 496 ngx_log_error(NGX_LOG_ALERT, m->log, 0, |
496 "trying to unlock the free mutex " PTR_FMT, m); | 497 "trying to unlock the free mutex %p", m); |
497 return NGX_ERROR; | 498 return NGX_ERROR; |
498 } | 499 } |
499 | 500 |
500 /* free the mutex */ | 501 /* free the mutex */ |
501 | 502 |
502 #if 0 | 503 #if 0 |
503 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 504 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
504 "unlock mutex " PTR_FMT " lock:%X", m, old); | 505 "unlock mutex %p lock:%XD", m, old); |
505 #endif | 506 #endif |
506 | 507 |
507 for ( ;; ) { | 508 for ( ;; ) { |
508 lock = old & ~NGX_MUTEX_LOCK_BUSY; | 509 lock = old & ~NGX_MUTEX_LOCK_BUSY; |
509 | 510 |
514 old = m->lock; | 515 old = m->lock; |
515 } | 516 } |
516 | 517 |
517 if (m->semid == -1) { | 518 if (m->semid == -1) { |
518 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 519 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
519 "mutex " PTR_FMT " is unlocked", m); | 520 "mutex %p is unlocked", m); |
520 | 521 |
521 return NGX_OK; | 522 return NGX_OK; |
522 } | 523 } |
523 | 524 |
524 /* check whether we need to wake up a waiting thread */ | 525 /* check whether we need to wake up a waiting thread */ |
544 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { | 545 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
545 | 546 |
546 /* wake up the thread that waits on semaphore */ | 547 /* wake up the thread that waits on semaphore */ |
547 | 548 |
548 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 549 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
549 "wake up mutex " PTR_FMT "", m); | 550 "wake up mutex %p", m); |
550 | 551 |
551 op.sem_num = 0; | 552 op.sem_num = 0; |
552 op.sem_op = 1; | 553 op.sem_op = 1; |
553 op.sem_flg = 0; | 554 op.sem_flg = 0; |
554 | 555 |
555 if (semop(m->semid, &op, 1) == -1) { | 556 if (semop(m->semid, &op, 1) == -1) { |
556 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 557 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
557 "semop() failed while waking up on mutex " | 558 "semop() failed while waking up on mutex %p", m); |
558 PTR_FMT, m); | |
559 return NGX_ERROR; | 559 return NGX_ERROR; |
560 } | 560 } |
561 | 561 |
562 break; | 562 break; |
563 } | 563 } |
564 | 564 |
565 old = m->lock; | 565 old = m->lock; |
566 } | 566 } |
567 | 567 |
568 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 568 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
569 "mutex " PTR_FMT " is unlocked", m); | 569 "mutex %p is unlocked", m); |
570 | 570 |
571 return NGX_OK; | 571 return NGX_OK; |
572 } | 572 } |
573 | 573 |
574 | 574 |
645 if (ngx_mutex_unlock(m) == NGX_ERROR) { | 645 if (ngx_mutex_unlock(m) == NGX_ERROR) { |
646 return NGX_ERROR; | 646 return NGX_ERROR; |
647 } | 647 } |
648 | 648 |
649 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, | 649 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
650 "cv " PTR_FMT " wait, kq:%d, signo:%d", | 650 "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); |
651 cv, cv->kq, cv->signo); | |
652 | 651 |
653 for ( ;; ) { | 652 for ( ;; ) { |
654 n = kevent(cv->kq, NULL, 0, &kev, 1, NULL); | 653 n = kevent(cv->kq, NULL, 0, &kev, 1, NULL); |
655 | 654 |
656 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, | 655 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, |
657 "cv " PTR_FMT " kevent: %d", cv, n); | 656 "cv %p kevent: %d", cv, n); |
658 | 657 |
659 if (n == -1) { | 658 if (n == -1) { |
660 err = ngx_errno; | 659 err = ngx_errno; |
661 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, | 660 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, |
662 cv->log, ngx_errno, | 661 cv->log, ngx_errno, |
663 "kevent() failed while waiting condition variable " | 662 "kevent() failed while waiting condition variable %p", |
664 PTR_FMT, cv); | 663 cv); |
665 | 664 |
666 if (err == NGX_EINTR) { | 665 if (err == NGX_EINTR) { |
667 break; | 666 break; |
668 } | 667 } |
669 | 668 |
671 } | 670 } |
672 | 671 |
673 if (n == 0) { | 672 if (n == 0) { |
674 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, | 673 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
675 "kevent() returned no events " | 674 "kevent() returned no events " |
676 "while waiting condition variable " PTR_FMT, | 675 "while waiting condition variable %p", |
677 cv); | 676 cv); |
678 continue; | 677 continue; |
679 } | 678 } |
680 | 679 |
681 if (kev.filter != EVFILT_SIGNAL) { | 680 if (kev.filter != EVFILT_SIGNAL) { |
682 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, | 681 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
683 "kevent() returned unexpected events: %d " | 682 "kevent() returned unexpected events: %d " |
684 "while waiting condition variable " PTR_FMT, | 683 "while waiting condition variable %p", |
685 kev.filter, cv); | 684 kev.filter, cv); |
686 continue; | 685 continue; |
687 } | 686 } |
688 | 687 |
689 if (kev.ident != (uintptr_t) cv->signo) { | 688 if (kev.ident != (uintptr_t) cv->signo) { |
690 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, | 689 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
691 "kevent() returned unexpected signal: %d ", | 690 "kevent() returned unexpected signal: %d ", |
692 "while waiting condition variable " PTR_FMT, | 691 "while waiting condition variable %p", |
693 kev.ident, cv); | 692 kev.ident, cv); |
694 continue; | 693 continue; |
695 } | 694 } |
696 | 695 |
697 break; | 696 break; |
698 } | 697 } |
699 | 698 |
700 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, | 699 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); |
701 "cv " PTR_FMT " is waked up", cv); | |
702 | 700 |
703 if (ngx_mutex_lock(m) == NGX_ERROR) { | 701 if (ngx_mutex_lock(m) == NGX_ERROR) { |
704 return NGX_ERROR; | 702 return NGX_ERROR; |
705 } | 703 } |
706 | 704 |
711 ngx_int_t ngx_cond_signal(ngx_cond_t *cv) | 709 ngx_int_t ngx_cond_signal(ngx_cond_t *cv) |
712 { | 710 { |
713 ngx_err_t err; | 711 ngx_err_t err; |
714 | 712 |
715 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, | 713 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
716 "cv " PTR_FMT " to signal " PID_T_FMT " %d", | 714 "cv %p to signal %P %d", |
717 cv, cv->tid, cv->signo); | 715 cv, cv->tid, cv->signo); |
718 | 716 |
719 if (kill(cv->tid, cv->signo) == -1) { | 717 if (kill(cv->tid, cv->signo) == -1) { |
720 | 718 |
721 err = ngx_errno; | 719 err = ngx_errno; |
722 | 720 |
723 ngx_log_error(NGX_LOG_ALERT, cv->log, err, | 721 ngx_log_error(NGX_LOG_ALERT, cv->log, err, |
724 "kill() failed while signaling condition variable " | 722 "kill() failed while signaling condition variable %p", cv); |
725 PTR_FMT, cv); | |
726 | 723 |
727 if (err == NGX_ESRCH) { | 724 if (err == NGX_ESRCH) { |
728 cv->tid = -1; | 725 cv->tid = -1; |
729 } | 726 } |
730 | 727 |
731 return NGX_ERROR; | 728 return NGX_ERROR; |
732 } | 729 } |
733 | 730 |
734 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, | 731 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv); |
735 "cv " PTR_FMT " is signaled", cv); | |
736 | 732 |
737 return NGX_OK; | 733 return NGX_OK; |
738 } | 734 } |