Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_freebsd_rfork_thread.c @ 4597:4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Not using full chain passed is ok as consumers are expected to check
event's ready flag to determine if another call is needed, not the
returned size.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 17 Apr 2012 09:13:58 +0000 |
parents | 67653855682e |
children | 15a7deeaa19a |
rev | line source |
---|---|
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
1 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
5 */ |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
6 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
8 #include <ngx_config.h> |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
9 #include <ngx_core.h> |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
10 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
11 /* |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
12 * The threads implementation uses the rfork(RFPROC|RFTHREAD|RFMEM) syscall |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
13 * to create threads. All threads use the stacks of the same size mmap()ed |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
14 * below the main stack. Thus the current thread id is determined via |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
15 * the stack pointer value. |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
16 * |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
17 * The mutex implementation uses the ngx_atomic_cmp_set() operation |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
18 * to acquire a mutex and the SysV semaphore to wait on a mutex and to wake up |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
19 * the waiting threads. The light mutex does not use semaphore, so after |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
20 * spinning in the lock the thread calls sched_yield(). However the light |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
21 * mutexes are intended to be used with the "trylock" operation only. |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
22 * The SysV semop() is a cheap syscall, particularly if it has little sembuf's |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
23 * and does not use SEM_UNDO. |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
24 * |
461 | 25 * The condition variable implementation uses the signal #64. |
26 * The signal handler is SIG_IGN so the kill() is a cheap syscall. | |
27 * The thread waits a signal in kevent(). The use of the EVFILT_SIGNAL | |
28 * is safe since FreeBSD 4.10-STABLE. | |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
29 * |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
30 * This threads implementation currently works on i386 (486+) and amd64 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
31 * platforms only. |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
32 */ |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
33 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
34 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
35 char *ngx_freebsd_kern_usrstack; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
36 size_t ngx_thread_stack_size; |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
39 static size_t rz_size; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
40 static size_t usable_stack_size; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
41 static char *last_stack; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
42 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
43 static ngx_uint_t nthreads; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
44 static ngx_uint_t max_threads; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
45 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
46 static ngx_uint_t nkeys; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
47 static ngx_tid_t *tids; /* the threads tids array */ |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
48 void **ngx_tls; /* the threads tls's array */ |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
49 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
50 /* the thread-safe libc errno */ |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
51 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
52 static int errno0; /* the main thread's errno */ |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
53 static int *errnos; /* the threads errno's array */ |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
563 | 55 int * |
56 __error() | |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
57 { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
58 int tid; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
59 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
60 tid = ngx_gettid(); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
61 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
62 return tid ? &errnos[tid - 1] : &errno0; |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 } |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
66 /* |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
67 * __isthreaded enables the spinlocks in some libc functions, i.e. in malloc() |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
68 * and some other places. Nevertheless we protect our malloc()/free() calls |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
69 * by own mutex that is more efficient than the spinlock. |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
70 * |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
71 * _spinlock() is a weak referenced stub in src/lib/libc/gen/_spinlock_stub.c |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
72 * that does nothing. |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
73 */ |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
74 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
75 extern int __isthreaded; |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
76 |
563 | 77 void |
78 _spinlock(ngx_atomic_t *lock) | |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
79 { |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
80 ngx_int_t tries; |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
81 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
82 tries = 0; |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
83 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
84 for ( ;; ) { |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
85 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
86 if (*lock) { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
87 if (ngx_ncpu > 1 && tries++ < 1000) { |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
88 continue; |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
89 } |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
90 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
91 sched_yield(); |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
92 tries = 0; |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
93 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
94 } else { |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
95 if (ngx_atomic_cmp_set(lock, 0, 1)) { |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
96 return; |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
97 } |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
98 } |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
99 } |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
100 } |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
101 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
102 |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
103 /* |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
104 * Before FreeBSD 5.1 _spinunlock() is a simple #define in |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
105 * src/lib/libc/include/spinlock.h that zeroes lock. |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
106 * |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
107 * Since FreeBSD 5.1 _spinunlock() is a weak referenced stub in |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
108 * src/lib/libc/gen/_spinlock_stub.c that does nothing. |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
109 */ |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
110 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
111 #ifndef _spinunlock |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
112 |
563 | 113 void |
114 _spinunlock(ngx_atomic_t *lock) | |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
115 { |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
116 *lock = 0; |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
117 } |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
118 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
119 #endif |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
120 |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
121 |
563 | 122 ngx_err_t |
123 ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg), | |
124 void *arg, ngx_log_t *log) | |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 { |
461 | 126 ngx_pid_t id; |
127 ngx_err_t err; | |
128 char *stack, *stack_top; | |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
129 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
130 if (nthreads >= max_threads) { |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
131 ngx_log_error(NGX_LOG_CRIT, log, 0, |
461 | 132 "no more than %ui threads can be created", max_threads); |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
133 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
134 } |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
136 last_stack -= ngx_thread_stack_size; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
137 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
138 stack = mmap(last_stack, usable_stack_size, PROT_READ|PROT_WRITE, |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
139 MAP_STACK, -1, 0); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
140 |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
141 if (stack == MAP_FAILED) { |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
142 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
461 | 143 "mmap(%p:%uz, MAP_STACK) thread stack failed", |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
144 last_stack, usable_stack_size); |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
145 return NGX_ERROR; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
146 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
147 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
148 if (stack != last_stack) { |
461 | 149 ngx_log_error(NGX_LOG_ALERT, log, 0, |
150 "stack %p address was changed to %p", last_stack, stack); | |
151 return NGX_ERROR; | |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
152 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
153 |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
154 stack_top = stack + usable_stack_size; |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
155 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
156 ngx_log_debug2(NGX_LOG_DEBUG_CORE, log, 0, |
461 | 157 "thread stack: %p-%p", stack, stack_top); |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
158 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
159 ngx_set_errno(0); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
160 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
161 id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
162 (ngx_rfork_thread_func_pt) func, arg); |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
163 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
164 err = ngx_errno; |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
166 if (id == -1) { |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
167 ngx_log_error(NGX_LOG_ALERT, log, err, "rfork() failed"); |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
168 |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
169 } else { |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 *tid = id; |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
171 nthreads = (ngx_freebsd_kern_usrstack - stack_top) |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
172 / ngx_thread_stack_size; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
173 tids[nthreads] = id; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
174 |
461 | 175 ngx_log_debug1(NGX_LOG_DEBUG_CORE, log, 0, "rfork()ed thread: %P", id); |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
176 } |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 return err; |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 } |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
563 | 182 ngx_int_t |
183 ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) | |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
185 char *red_zone, *zone; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
186 size_t len; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
187 ngx_int_t i; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
188 struct sigaction sa; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
189 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
190 max_threads = n + 1; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
191 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
192 for (i = 0; i < n; i++) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
193 ngx_memzero(&sa, sizeof(struct sigaction)); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
194 sa.sa_handler = SIG_IGN; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
195 sigemptyset(&sa.sa_mask); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
196 if (sigaction(NGX_CV_SIGNAL, &sa, NULL) == -1) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
197 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
198 "sigaction(%d, SIG_IGN) failed", NGX_CV_SIGNAL); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
199 return NGX_ERROR; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
200 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
201 } |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
202 |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
203 len = sizeof(ngx_freebsd_kern_usrstack); |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
204 if (sysctlbyname("kern.usrstack", &ngx_freebsd_kern_usrstack, &len, |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
205 NULL, 0) == -1) |
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
206 { |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
207 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
208 "sysctlbyname(kern.usrstack) failed"); |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
209 return NGX_ERROR; |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 } |
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
212 /* the main thread stack red zone */ |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
305
diff
changeset
|
213 rz_size = ngx_pagesize; |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
214 red_zone = ngx_freebsd_kern_usrstack - (size + rz_size); |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
215 |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
216 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cycle->log, 0, |
461 | 217 "usrstack: %p red zone: %p", |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
218 ngx_freebsd_kern_usrstack, red_zone); |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
220 zone = mmap(red_zone, rz_size, PROT_NONE, MAP_ANON, -1, 0); |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
221 if (zone == MAP_FAILED) { |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
222 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
461 | 223 "mmap(%p:%uz, PROT_NONE, MAP_ANON) red zone failed", |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
224 red_zone, rz_size); |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
225 return NGX_ERROR; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
226 } |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
227 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
228 if (zone != red_zone) { |
270
7bb9562216ce
nginx-0.0.2-2004-02-25-23:16:15 import
Igor Sysoev <igor@sysoev.ru>
parents:
267
diff
changeset
|
229 ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, |
461 | 230 "red zone %p address was changed to %p", red_zone, zone); |
231 return NGX_ERROR; | |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
232 } |
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
233 |
461 | 234 /* create the thread errno' array */ |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
235 |
501 | 236 errnos = ngx_calloc(n * sizeof(int), cycle->log); |
237 if (errnos == NULL) { | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
238 return NGX_ERROR; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
239 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
240 |
461 | 241 /* create the thread tids array */ |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
242 |
501 | 243 tids = ngx_calloc((n + 1) * sizeof(ngx_tid_t), cycle->log); |
244 if (tids == NULL) { | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
245 return NGX_ERROR; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
246 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
247 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
248 tids[0] = ngx_pid; |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
249 |
461 | 250 /* create the thread tls' array */ |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
251 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
252 ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *), |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
253 cycle->log); |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
254 if (ngx_tls == NULL) { |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
255 return NGX_ERROR; |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
256 } |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
257 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
258 nthreads = 1; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
259 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
260 last_stack = zone + rz_size; |
86
3973260705cc
nginx-0.0.1-2003-05-12-19:52:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
85
diff
changeset
|
261 usable_stack_size = size; |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
262 ngx_thread_stack_size = size + rz_size; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
263 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
264 /* allow the spinlock in libc malloc() */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
265 __isthreaded = 1; |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
266 |
271
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
267 ngx_threaded = 1; |
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
268 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
269 return NGX_OK; |
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
270 } |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
271 |
84
fab4cb00fe5b
nginx-0.0.1-2003-05-06-21:03:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
272 |
563 | 273 ngx_tid_t |
274 ngx_thread_self() | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
275 { |
501 | 276 ngx_int_t tid; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
277 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
278 tid = ngx_gettid(); |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
279 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
280 if (tids == NULL) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
281 return ngx_pid; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
282 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
283 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
284 return tids[tid]; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
285 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
286 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
287 |
563 | 288 ngx_err_t |
289 ngx_thread_key_create(ngx_tls_key_t *key) | |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
290 { |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
291 if (nkeys >= NGX_THREAD_KEYS_MAX) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
292 return NGX_ENOMEM; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
293 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
294 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
295 *key = nkeys++; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
296 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
297 return 0; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
298 } |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
299 |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
300 |
563 | 301 ngx_err_t |
302 ngx_thread_set_tls(ngx_tls_key_t key, void *value) | |
381
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
303 { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
304 if (key >= NGX_THREAD_KEYS_MAX) { |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
305 return NGX_EINVAL; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
306 } |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
307 |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
308 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; |
02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
379
diff
changeset
|
309 return 0; |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
310 } |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
311 |
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
312 |
563 | 313 ngx_mutex_t * |
314 ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
315 { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
316 ngx_mutex_t *m; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
317 union semun op; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
318 |
501 | 319 m = ngx_alloc(sizeof(ngx_mutex_t), log); |
320 if (m == NULL) { | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
321 return NULL; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
322 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
323 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
324 m->lock = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
325 m->log = log; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
326 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
327 if (flags & NGX_MUTEX_LIGHT) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
328 m->semid = -1; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
329 return m; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
330 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
331 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
332 m->semid = semget(IPC_PRIVATE, 1, SEM_R|SEM_A); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
333 if (m->semid == -1) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
334 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "semget() failed"); |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
335 return NULL; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
336 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
337 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
338 op.val = 0; |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
339 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
340 if (semctl(m->semid, 0, SETVAL, op) == -1) { |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
341 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "semctl(SETVAL) failed"); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
342 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
343 if (semctl(m->semid, 0, IPC_RMID) == -1) { |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
344 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
345 "semctl(IPC_RMID) failed"); |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
346 } |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
347 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
348 return NULL; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
349 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
350 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
351 return m; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
352 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
353 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
354 |
563 | 355 void |
356 ngx_mutex_destroy(ngx_mutex_t *m) | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
357 { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
358 if (semctl(m->semid, 0, IPC_RMID) == -1) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
359 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
360 "semctl(IPC_RMID) failed"); |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
361 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
362 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
266
diff
changeset
|
363 ngx_free((void *) m); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
364 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
365 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
366 |
563 | 367 ngx_int_t |
368 ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
369 { |
501 | 370 uint32_t lock, old; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
371 ngx_uint_t tries; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
372 struct sembuf op; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
373 |
271
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
374 if (!ngx_threaded) { |
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
375 return NGX_OK; |
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
376 } |
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
377 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
378 #if (NGX_DEBUG) |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
379 if (try) { |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
380 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 381 "try lock mutex %p lock:%XD", m, m->lock); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
382 } else { |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
383 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 384 "lock mutex %p lock:%XD", m, m->lock); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
385 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
386 #endif |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
387 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
388 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
389 tries = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
390 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
391 for ( ;; ) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
392 if (old & NGX_MUTEX_LOCK_BUSY) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
393 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
394 if (try) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
395 return NGX_AGAIN; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
396 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
397 |
469 | 398 if (ngx_ncpu > 1 && tries++ < 1000) { |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
399 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
400 /* the spinlock is used only on the SMP system */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
401 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
402 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
403 continue; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
404 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
405 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
406 if (m->semid == -1) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
407 sched_yield(); |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
408 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
409 tries = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
410 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
411 continue; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
412 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
413 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
414 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 415 "mutex %p lock:%XD", m, m->lock); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
416 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
417 /* |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
418 * The mutex is locked so we increase a number |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
419 * of the threads that are waiting on the mutex |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
420 */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
421 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
422 lock = old + 1; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
423 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
424 if ((lock & ~NGX_MUTEX_LOCK_BUSY) > nthreads) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
425 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
461 | 426 "%D threads wait for mutex %p, " |
427 "while only %ui threads are available", | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
428 lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); |
563 | 429 ngx_abort(); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
430 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
431 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
432 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
433 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
434 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 435 "wait mutex %p lock:%XD", m, m->lock); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
436 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
437 /* |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
438 * The number of the waiting threads has been increased |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
439 * and we would wait on the SysV semaphore. |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
440 * A semaphore should wake up us more efficiently than |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
441 * a simple sched_yield() or usleep(). |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
442 */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
443 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
444 op.sem_num = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
445 op.sem_op = -1; |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
446 op.sem_flg = 0; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
447 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
448 if (semop(m->semid, &op, 1) == -1) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
449 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
461 | 450 "semop() failed while waiting on mutex %p", m); |
563 | 451 ngx_abort(); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
452 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
453 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
454 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 455 "mutex waked up %p lock:%XD", m, m->lock); |
372
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
456 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
457 tries = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
458 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
459 continue; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
460 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
461 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
462 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
463 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
464 } else { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
465 lock = old | NGX_MUTEX_LOCK_BUSY; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
466 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
467 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
468 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
469 /* we locked the mutex */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
470 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
471 break; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
472 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
473 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
474 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
475 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
476 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
477 if (tries++ > 1000) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
478 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
479 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 480 "mutex %p is contested", m); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
481 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
482 /* the mutex is probably contested so we are giving up now */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
483 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
484 sched_yield(); |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
485 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
486 tries = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
487 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
488 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
489 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
490 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
491 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 492 "mutex %p is locked, lock:%XD", m, m->lock); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
493 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
494 return NGX_OK; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
495 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
496 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
497 |
563 | 498 void |
499 ngx_mutex_unlock(ngx_mutex_t *m) | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
500 { |
501 | 501 uint32_t lock, old; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
502 struct sembuf op; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
503 |
271
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
504 if (!ngx_threaded) { |
563 | 505 return; |
271
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
506 } |
e16dfb9b9afa
nginx-0.0.2-2004-02-26-20:10:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
270
diff
changeset
|
507 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
508 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
509 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
510 if (!(old & NGX_MUTEX_LOCK_BUSY)) { |
272
d4e65d74db9f
nginx-0.0.2-2004-03-01-00:03:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
271
diff
changeset
|
511 ngx_log_error(NGX_LOG_ALERT, m->log, 0, |
461 | 512 "trying to unlock the free mutex %p", m); |
563 | 513 ngx_abort(); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
514 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
515 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
516 /* free the mutex */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
517 |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
518 #if 0 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
519 ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 520 "unlock mutex %p lock:%XD", m, old); |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
521 #endif |
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
522 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
523 for ( ;; ) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
524 lock = old & ~NGX_MUTEX_LOCK_BUSY; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
525 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
526 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
527 break; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
528 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
529 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
530 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
531 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
532 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
533 if (m->semid == -1) { |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
534 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 535 "mutex %p is unlocked", m); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
536 |
563 | 537 return; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
538 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
539 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
540 /* check whether we need to wake up a waiting thread */ |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
541 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
542 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
543 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
544 for ( ;; ) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
545 if (old & NGX_MUTEX_LOCK_BUSY) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
546 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
547 /* the mutex is just locked by another thread */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
548 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
549 break; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
550 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
551 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
552 if (old == 0) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
553 break; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
554 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
555 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
556 /* there are the waiting threads */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
557 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
558 lock = old - 1; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
559 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
560 if (ngx_atomic_cmp_set(&m->lock, old, lock)) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
561 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
562 /* wake up the thread that waits on semaphore */ |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
563 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
564 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 565 "wake up mutex %p", m); |
372
c9fdfccebc49
nginx-0.0.7-2004-06-29-01:03:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
566 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
567 op.sem_num = 0; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
568 op.sem_op = 1; |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
569 op.sem_flg = 0; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
570 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
571 if (semop(m->semid, &op, 1) == -1) { |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
572 ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, |
461 | 573 "semop() failed while waking up on mutex %p", m); |
563 | 574 ngx_abort(); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
575 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
576 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
577 break; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
578 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
579 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
580 old = m->lock; |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
581 } |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
582 |
379
73688d5d7fc3
nginx-0.0.7-2004-07-06-20:12:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
583 ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, |
461 | 584 "mutex %p is unlocked", m); |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
585 |
563 | 586 return; |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
208
diff
changeset
|
587 } |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
588 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
589 |
563 | 590 ngx_cond_t * |
591 ngx_cond_init(ngx_log_t *log) | |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
592 { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
593 ngx_cond_t *cv; |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
594 |
501 | 595 cv = ngx_alloc(sizeof(ngx_cond_t), log); |
596 if (cv == NULL) { | |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
597 return NULL; |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
598 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
599 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
600 cv->signo = NGX_CV_SIGNAL; |
469 | 601 cv->tid = -1; |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
602 cv->log = log; |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
603 cv->kq = -1; |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
604 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
605 return cv; |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
606 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
607 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
608 |
563 | 609 void |
610 ngx_cond_destroy(ngx_cond_t *cv) | |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
611 { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
612 if (close(cv->kq) == -1) { |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
613 ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
614 "kqueue close() failed"); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
615 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
616 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
617 ngx_free(cv); |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
618 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
619 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
620 |
563 | 621 ngx_int_t |
622 ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) | |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
623 { |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
624 int n; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
625 ngx_err_t err; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
626 struct kevent kev; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
627 struct timespec ts; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
628 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
629 if (cv->kq == -1) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
630 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
631 /* |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
632 * We have to add the EVFILT_SIGNAL filter in the rfork()ed thread. |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
633 * Otherwise the thread would not get a signal event. |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
634 * |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
635 * However, we have not to open the kqueue in the thread, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
636 * it is simply handy do it together. |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
637 */ |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
638 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
639 cv->kq = kqueue(); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
640 if (cv->kq == -1) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
641 ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, "kqueue() failed"); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
642 return NGX_ERROR; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
643 } |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
644 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
645 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
646 "cv kq:%d signo:%d", cv->kq, cv->signo); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
647 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
648 kev.ident = cv->signo; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
649 kev.filter = EVFILT_SIGNAL; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
650 kev.flags = EV_ADD; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
651 kev.fflags = 0; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
652 kev.data = 0; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
653 kev.udata = NULL; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
654 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
655 ts.tv_sec = 0; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
656 ts.tv_nsec = 0; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
657 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
658 if (kevent(cv->kq, &kev, 1, NULL, 0, &ts) == -1) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
659 ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, "kevent() failed"); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
660 return NGX_ERROR; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
661 } |
469 | 662 |
663 cv->tid = ngx_thread_self(); | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
664 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
665 |
563 | 666 ngx_mutex_unlock(m); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
667 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
668 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
461 | 669 "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
670 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
671 for ( ;; ) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
672 n = kevent(cv->kq, NULL, 0, &kev, 1, NULL); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
673 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
674 ngx_log_debug2(NGX_LOG_DEBUG_CORE, cv->log, 0, |
461 | 675 "cv %p kevent: %d", cv, n); |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
676 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
677 if (n == -1) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
678 err = ngx_errno; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
679 ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
680 cv->log, ngx_errno, |
461 | 681 "kevent() failed while waiting condition variable %p", |
682 cv); | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
683 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
684 if (err == NGX_EINTR) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
685 break; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
686 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
687 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
688 return NGX_ERROR; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
689 } |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
690 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
691 if (n == 0) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
692 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
693 "kevent() returned no events " |
461 | 694 "while waiting condition variable %p", |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
695 cv); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
696 continue; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
697 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
698 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
699 if (kev.filter != EVFILT_SIGNAL) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
700 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
701 "kevent() returned unexpected events: %d " |
461 | 702 "while waiting condition variable %p", |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
703 kev.filter, cv); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
704 continue; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
705 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
706 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
707 if (kev.ident != (uintptr_t) cv->signo) { |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
708 ngx_log_error(NGX_LOG_ALERT, cv->log, 0, |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
709 "kevent() returned unexpected signal: %d ", |
461 | 710 "while waiting condition variable %p", |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
711 kev.ident, cv); |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
712 continue; |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
713 } |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
714 |
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
715 break; |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
716 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
717 |
461 | 718 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
719 |
563 | 720 ngx_mutex_lock(m); |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
721 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
722 return NGX_OK; |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
723 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
724 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
725 |
563 | 726 ngx_int_t |
727 ngx_cond_signal(ngx_cond_t *cv) | |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
728 { |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
729 ngx_err_t err; |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
730 |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
731 ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, |
461 | 732 "cv %p to signal %P %d", |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
733 cv, cv->tid, cv->signo); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
734 |
469 | 735 if (cv->tid == -1) { |
736 return NGX_OK; | |
737 } | |
738 | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
375
diff
changeset
|
739 if (kill(cv->tid, cv->signo) == -1) { |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
740 |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
741 err = ngx_errno; |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
742 |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
743 ngx_log_error(NGX_LOG_ALERT, cv->log, err, |
461 | 744 "kill() failed while signaling condition variable %p", cv); |
377
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
745 |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
746 if (err == NGX_ESRCH) { |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
747 cv->tid = -1; |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
748 } |
41437e4fd9b4
nginx-0.0.7-2004-07-05-19:08:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
749 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
750 return NGX_ERROR; |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
751 } |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
752 |
461 | 753 ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is signaled", cv); |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
754 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
755 return NGX_OK; |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
756 } |