Mercurial > hg > nginx-vendor-current
comparison src/os/unix/ngx_freebsd_rfork_thread.c @ 112:408f195b3482 NGINX_0_3_3
nginx 0.3.3
*) Change: the "bl" and "af" parameters of the "listen" directive was
renamed to the "backlog" and "accept_filter".
*) Feature: the "rcvbuf" and "sndbuf" parameters of the "listen"
directive.
*) Change: the "$msec" log parameter does not require now the
additional the gettimeofday() system call.
*) Feature: the -t switch now tests the "listen" directives.
*) Bugfix: if the invalid address was specified in the "listen"
directive, then after the -HUP signal nginx left an open socket in
the CLOSED state.
*) Bugfix: the mime type may be incorrectly set to default value for
index file with variable in the name; bug appeared in 0.3.0.
*) Feature: the "timer_resolution" directive.
*) Feature: the millisecond "$upstream_response_time" log parameter.
*) Bugfix: a temporary file with client request body now is removed
just after the response header was transferred to a client.
*) Bugfix: OpenSSL 0.9.6 compatibility.
*) Bugfix: the SSL certificate and key file paths could not be relative.
*) Bugfix: the "ssl_prefer_server_ciphers" directive did not work in
the ngx_imap_ssl_module.
*) Bugfix: the "ssl_protocols" directive allowed to specify the single
protocol only.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 19 Oct 2005 00:00:00 +0400 |
parents | 72eb30262aac |
children | d0f7a625f27c |
comparison
equal
deleted
inserted
replaced
111:a175b609c76d | 112:408f195b3482 |
---|---|
49 /* the thread-safe libc errno */ | 49 /* the thread-safe libc errno */ |
50 | 50 |
51 static int errno0; /* the main thread's errno */ | 51 static int errno0; /* the main thread's errno */ |
52 static int *errnos; /* the threads errno's array */ | 52 static int *errnos; /* the threads errno's array */ |
53 | 53 |
54 int *__error() | 54 int * |
55 __error() | |
55 { | 56 { |
56 int tid; | 57 int tid; |
57 | 58 |
58 tid = ngx_gettid(); | 59 tid = ngx_gettid(); |
59 | 60 |
70 * that does nothing. | 71 * that does nothing. |
71 */ | 72 */ |
72 | 73 |
73 extern int __isthreaded; | 74 extern int __isthreaded; |
74 | 75 |
75 void _spinlock(ngx_atomic_t *lock) | 76 void |
77 _spinlock(ngx_atomic_t *lock) | |
76 { | 78 { |
77 ngx_int_t tries; | 79 ngx_int_t tries; |
78 | 80 |
79 tries = 0; | 81 tries = 0; |
80 | 82 |
105 * src/lib/libc/gen/_spinlock_stub.c that does nothing. | 107 * src/lib/libc/gen/_spinlock_stub.c that does nothing. |
106 */ | 108 */ |
107 | 109 |
108 #ifndef _spinunlock | 110 #ifndef _spinunlock |
109 | 111 |
110 void _spinunlock(ngx_atomic_t *lock) | 112 void |
113 _spinunlock(ngx_atomic_t *lock) | |
111 { | 114 { |
112 *lock = 0; | 115 *lock = 0; |
113 } | 116 } |
114 | 117 |
115 #endif | 118 #endif |
116 | 119 |
117 | 120 |
118 ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, | 121 ngx_err_t |
119 ngx_log_t *log) | 122 ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg), |
123 void *arg, ngx_log_t *log) | |
120 { | 124 { |
121 ngx_pid_t id; | 125 ngx_pid_t id; |
122 ngx_err_t err; | 126 ngx_err_t err; |
123 char *stack, *stack_top; | 127 char *stack, *stack_top; |
124 | 128 |
172 | 176 |
173 return err; | 177 return err; |
174 } | 178 } |
175 | 179 |
176 | 180 |
177 ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) | 181 ngx_int_t |
182 ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) | |
178 { | 183 { |
179 char *red_zone, *zone; | 184 char *red_zone, *zone; |
180 size_t len; | 185 size_t len; |
181 ngx_int_t i; | 186 ngx_int_t i; |
182 struct sigaction sa; | 187 struct sigaction sa; |
262 | 267 |
263 return NGX_OK; | 268 return NGX_OK; |
264 } | 269 } |
265 | 270 |
266 | 271 |
267 ngx_tid_t ngx_thread_self() | 272 ngx_tid_t |
273 ngx_thread_self() | |
268 { | 274 { |
269 ngx_int_t tid; | 275 ngx_int_t tid; |
270 | 276 |
271 tid = ngx_gettid(); | 277 tid = ngx_gettid(); |
272 | 278 |
276 | 282 |
277 return tids[tid]; | 283 return tids[tid]; |
278 } | 284 } |
279 | 285 |
280 | 286 |
281 ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) | 287 ngx_err_t |
288 ngx_thread_key_create(ngx_tls_key_t *key) | |
282 { | 289 { |
283 if (nkeys >= NGX_THREAD_KEYS_MAX) { | 290 if (nkeys >= NGX_THREAD_KEYS_MAX) { |
284 return NGX_ENOMEM; | 291 return NGX_ENOMEM; |
285 } | 292 } |
286 | 293 |
288 | 295 |
289 return 0; | 296 return 0; |
290 } | 297 } |
291 | 298 |
292 | 299 |
293 ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) | 300 ngx_err_t |
301 ngx_thread_set_tls(ngx_tls_key_t key, void *value) | |
294 { | 302 { |
295 if (key >= NGX_THREAD_KEYS_MAX) { | 303 if (key >= NGX_THREAD_KEYS_MAX) { |
296 return NGX_EINVAL; | 304 return NGX_EINVAL; |
297 } | 305 } |
298 | 306 |
299 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; | 307 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; |
300 return 0; | 308 return 0; |
301 } | 309 } |
302 | 310 |
303 | 311 |
304 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) | 312 ngx_mutex_t * |
313 ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) | |
305 { | 314 { |
306 ngx_mutex_t *m; | 315 ngx_mutex_t *m; |
307 union semun op; | 316 union semun op; |
308 | 317 |
309 m = ngx_alloc(sizeof(ngx_mutex_t), log); | 318 m = ngx_alloc(sizeof(ngx_mutex_t), log); |
340 | 349 |
341 return m; | 350 return m; |
342 } | 351 } |
343 | 352 |
344 | 353 |
345 void ngx_mutex_destroy(ngx_mutex_t *m) | 354 void |
355 ngx_mutex_destroy(ngx_mutex_t *m) | |
346 { | 356 { |
347 if (semctl(m->semid, 0, IPC_RMID) == -1) { | 357 if (semctl(m->semid, 0, IPC_RMID) == -1) { |
348 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 358 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
349 "semctl(IPC_RMID) failed"); | 359 "semctl(IPC_RMID) failed"); |
350 } | 360 } |
351 | 361 |
352 ngx_free((void *) m); | 362 ngx_free((void *) m); |
353 } | 363 } |
354 | 364 |
355 | 365 |
356 ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) | 366 ngx_int_t |
367 ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) | |
357 { | 368 { |
358 uint32_t lock, old; | 369 uint32_t lock, old; |
359 ngx_uint_t tries; | 370 ngx_uint_t tries; |
360 struct sembuf op; | 371 struct sembuf op; |
361 | 372 |
412 if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { | 423 if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { |
413 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 424 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
414 "%D threads wait for mutex %p, " | 425 "%D threads wait for mutex %p, " |
415 "while only %ui threads are available", | 426 "while only %ui threads are available", |
416 lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); | 427 lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); |
417 return NGX_ERROR; | 428 ngx_abort(); |
418 } | 429 } |
419 | 430 |
420 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { | 431 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
421 | 432 |
422 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 433 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
434 op.sem_flg = 0; | 445 op.sem_flg = 0; |
435 | 446 |
436 if (semop(m->semid, &op, 1) == -1) { | 447 if (semop(m->semid, &op, 1) == -1) { |
437 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 448 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
438 "semop() failed while waiting on mutex %p", m); | 449 "semop() failed while waiting on mutex %p", m); |
439 return NGX_ERROR; | 450 ngx_abort(); |
440 } | 451 } |
441 | 452 |
442 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 453 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
443 "mutex waked up %p lock:%XD", m, m->lock); | 454 "mutex waked up %p lock:%XD", m, m->lock); |
444 | 455 |
481 | 492 |
482 return NGX_OK; | 493 return NGX_OK; |
483 } | 494 } |
484 | 495 |
485 | 496 |
486 ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) | 497 void |
498 ngx_mutex_unlock(ngx_mutex_t *m) | |
487 { | 499 { |
488 uint32_t lock, old; | 500 uint32_t lock, old; |
489 struct sembuf op; | 501 struct sembuf op; |
490 | 502 |
491 if (!ngx_threaded) { | 503 if (!ngx_threaded) { |
492 return NGX_OK; | 504 return; |
493 } | 505 } |
494 | 506 |
495 old = m->lock; | 507 old = m->lock; |
496 | 508 |
497 if (!(old & NGX_MUTEX_LOCK_BUSY)) { | 509 if (!(old & NGX_MUTEX_LOCK_BUSY)) { |
498 ngx_log_error(NGX_LOG_ALERT, m->log, 0, | 510 ngx_log_error(NGX_LOG_ALERT, m->log, 0, |
499 "trying to unlock the free mutex %p", m); | 511 "trying to unlock the free mutex %p", m); |
500 return NGX_ERROR; | 512 ngx_abort(); |
501 } | 513 } |
502 | 514 |
503 /* free the mutex */ | 515 /* free the mutex */ |
504 | 516 |
505 #if 0 | 517 #if 0 |
519 | 531 |
520 if (m->semid == -1) { | 532 if (m->semid == -1) { |
521 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 533 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
522 "mutex %p is unlocked", m); | 534 "mutex %p is unlocked", m); |
523 | 535 |
524 return NGX_OK; | 536 return; |
525 } | 537 } |
526 | 538 |
527 /* check whether we need to wake up a waiting thread */ | 539 /* check whether we need to wake up a waiting thread */ |
528 | 540 |
529 old = m->lock; | 541 old = m->lock; |
556 op.sem_flg = 0; | 568 op.sem_flg = 0; |
557 | 569 |
558 if (semop(m->semid, &op, 1) == -1) { | 570 if (semop(m->semid, &op, 1) == -1) { |
559 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, | 571 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
560 "semop() failed while waking up on mutex %p", m); | 572 "semop() failed while waking up on mutex %p", m); |
561 return NGX_ERROR; | 573 ngx_abort(); |
562 } | 574 } |
563 | 575 |
564 break; | 576 break; |
565 } | 577 } |
566 | 578 |
568 } | 580 } |
569 | 581 |
570 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, | 582 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
571 "mutex %p is unlocked", m); | 583 "mutex %p is unlocked", m); |
572 | 584 |
573 return NGX_OK; | 585 return; |
574 } | 586 } |
575 | 587 |
576 | 588 |
577 ngx_cond_t *ngx_cond_init(ngx_log_t *log) | 589 ngx_cond_t * |
590 ngx_cond_init(ngx_log_t *log) | |
578 { | 591 { |
579 ngx_cond_t *cv; | 592 ngx_cond_t *cv; |
580 | 593 |
581 cv = ngx_alloc(sizeof(ngx_cond_t), log); | 594 cv = ngx_alloc(sizeof(ngx_cond_t), log); |
582 if (cv == NULL) { | 595 if (cv == NULL) { |
590 | 603 |
591 return cv; | 604 return cv; |
592 } | 605 } |
593 | 606 |
594 | 607 |
595 void ngx_cond_destroy(ngx_cond_t *cv) | 608 void |
609 ngx_cond_destroy(ngx_cond_t *cv) | |
596 { | 610 { |
597 if (close(cv->kq) == -1) { | 611 if (close(cv->kq) == -1) { |
598 ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, | 612 ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, |
599 "kqueue close() failed"); | 613 "kqueue close() failed"); |
600 } | 614 } |
601 | 615 |
602 ngx_free(cv); | 616 ngx_free(cv); |
603 } | 617 } |
604 | 618 |
605 | 619 |
606 ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) | 620 ngx_int_t |
621 ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) | |
607 { | 622 { |
608 int n; | 623 int n; |
609 ngx_err_t err; | 624 ngx_err_t err; |
610 struct kevent kev; | 625 struct kevent kev; |
611 struct timespec ts; | 626 struct timespec ts; |
645 } | 660 } |
646 | 661 |
647 cv->tid = ngx_thread_self(); | 662 cv->tid = ngx_thread_self(); |
648 } | 663 } |
649 | 664 |
650 if (ngx_mutex_unlock(m) == NGX_ERROR) { | 665 ngx_mutex_unlock(m); |
651 return NGX_ERROR; | |
652 } | |
653 | 666 |
654 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, | 667 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
655 "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); | 668 "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); |
656 | 669 |
657 for ( ;; ) { | 670 for ( ;; ) { |
701 break; | 714 break; |
702 } | 715 } |
703 | 716 |
704 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); | 717 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); |
705 | 718 |
706 if (ngx_mutex_lock(m) == NGX_ERROR) { | 719 ngx_mutex_lock(m); |
707 return NGX_ERROR; | |
708 } | |
709 | 720 |
710 return NGX_OK; | 721 return NGX_OK; |
711 } | 722 } |
712 | 723 |
713 | 724 |
714 ngx_int_t ngx_cond_signal(ngx_cond_t *cv) | 725 ngx_int_t |
726 ngx_cond_signal(ngx_cond_t *cv) | |
715 { | 727 { |
716 ngx_err_t err; | 728 ngx_err_t err; |
717 | 729 |
718 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, | 730 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
719 "cv %p to signal %P %d", | 731 "cv %p to signal %P %d", |