Mercurial > hg > nginx-quic
annotate src/core/ngx_palloc.c @ 2064:0835142149d2
refactor obscure code
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 25 Jun 2008 14:56:14 +0000 |
parents | 24eebb21b5d2 |
children | 25add486e7aa |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
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 |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
436
diff
changeset
|
5 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
87
diff
changeset
|
8 #include <ngx_core.h> |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2049 | 11 static void *ngx_palloc_block(ngx_pool_t *pool, size_t size); |
12 static void *ngx_palloc_large(ngx_pool_t *pool, size_t size); | |
13 | |
14 | |
501 | 15 ngx_pool_t * |
16 ngx_create_pool(size_t size, ngx_log_t *log) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 { |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
18 ngx_pool_t *p; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
501 | 20 p = ngx_alloc(size, log); |
21 if (p == NULL) { | |
527 | 22 return NULL; |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
23 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 |
2049 | 25 p->d.last = (u_char *) p + sizeof(ngx_pool_t); |
26 p->d.end = (u_char *) p + size; | |
27 p->d.next = NULL; | |
28 | |
2057
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
29 size = size - sizeof(ngx_pool_t); |
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
30 p->max = (size < NGX_MAX_ALLOC_FROM_POOL) ? size : NGX_MAX_ALLOC_FROM_POOL; |
24eebb21b5d2
fix max size allocated from pool
Igor Sysoev <igor@sysoev.ru>
parents:
2056
diff
changeset
|
31 |
581 | 32 p->current = p; |
33 p->chain = NULL; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 p->large = NULL; |
509 | 35 p->cleanup = NULL; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 p->log = log; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
41 |
501 | 42 void |
43 ngx_destroy_pool(ngx_pool_t *pool) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 { |
509 | 45 ngx_pool_t *p, *n; |
46 ngx_pool_large_t *l; | |
47 ngx_pool_cleanup_t *c; | |
48 | |
49 for (c = pool->cleanup; c; c = c->next) { | |
50 if (c->handler) { | |
1744 | 51 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
52 "run cleanup: %p", c); | |
509 | 53 c->handler(c->data); |
54 } | |
55 } | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
57 for (l = pool->large; l; l = l->next) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
58 |
461 | 59 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, "free: %p", l->alloc); |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
60 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
61 if (l->alloc) { |
477 | 62 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
63 } |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
64 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
66 #if (NGX_DEBUG) |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
67 |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
68 /* |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
69 * we could allocate the pool->log from this pool |
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
70 * so we can not use this log while the free()ing the pool |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
71 */ |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
72 |
2049 | 73 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
74 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
2049 | 75 "free: %p, unused: %uz", p, p->d.end - p->d.last); |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
76 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
77 if (n == NULL) { |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
78 break; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
128
diff
changeset
|
79 } |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
80 } |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
81 |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
82 #endif |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
83 |
2049 | 84 for (p = pool, n = pool->d.next; /* void */; p = n, n = n->d.next) { |
477 | 85 ngx_free(p); |
128
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
86 |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
87 if (n == NULL) { |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
88 break; |
1947c683490f
nginx-0.0.1-2003-08-08-19:13:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
126
diff
changeset
|
89 } |
126
fcc79370b9a8
nginx-0.0.1-2003-08-06-18:43:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
104
diff
changeset
|
90 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
92 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
93 |
501 | 94 void * |
95 ngx_palloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 { |
2049 | 97 u_char *m; |
98 ngx_pool_t *p; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
2049 | 100 if (size <= pool->max) { |
101 | |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
102 p = pool->current; |
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
103 |
2049 | 104 do { |
105 m = ngx_align_ptr(p->d.last, NGX_ALIGNMENT); | |
589 | 106 |
2049 | 107 if ((size_t) (p->d.end - m) >= size) { |
108 p->d.last = m + size; | |
1207
103988cef757
use memory optimization for i386 and amd64 only:
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
109 |
2049 | 110 return m; |
589 | 111 } |
104
7db96f59bc29
nginx-0.0.1-2003-06-12-09:54:39 import
Igor Sysoev <igor@sysoev.ru>
parents:
100
diff
changeset
|
112 |
2049 | 113 p = p->d.next; |
114 | |
115 } while (p); | |
116 | |
117 return ngx_palloc_block(pool, size); | |
118 } | |
119 | |
120 return ngx_palloc_large(pool, size); | |
121 } | |
122 | |
123 | |
124 void * | |
125 ngx_pnalloc(ngx_pool_t *pool, size_t size) | |
126 { | |
127 u_char *m; | |
128 ngx_pool_t *p; | |
129 | |
130 if (size <= pool->max) { | |
131 | |
132 p = pool->current; | |
133 | |
134 do { | |
135 m = p->d.last; | |
136 | |
137 if ((size_t) (p->d.end - m) >= size) { | |
138 p->d.last = m + size; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 return m; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
2049 | 143 p = p->d.next; |
144 | |
145 } while (p); | |
146 | |
147 return ngx_palloc_block(pool, size); | |
148 } | |
149 | |
150 return ngx_palloc_large(pool, size); | |
151 } | |
152 | |
581 | 153 |
2049 | 154 static void * |
155 ngx_palloc_block(ngx_pool_t *pool, size_t size) | |
156 { | |
157 u_char *m; | |
2055 | 158 size_t psize; |
2049 | 159 ngx_pool_t *p, *new, *current; |
931
87f456ff13b0
fix segfault in "out of memory" situation
Igor Sysoev <igor@sysoev.ru>
parents:
860
diff
changeset
|
160 |
2055 | 161 psize = (size_t) (pool->d.end - (u_char *) pool); |
162 | |
2056 | 163 m = ngx_alloc(psize, pool->log); |
164 if (m == NULL) { | |
2049 | 165 return NULL; |
166 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
167 |
2056 | 168 new = (ngx_pool_t *) m; |
169 | |
170 new->d.end = m + psize; | |
2055 | 171 new->d.next = NULL; |
172 | |
2056 | 173 m += sizeof(ngx_pool_data_t); |
174 new->d.last = m + size; | |
175 | |
2049 | 176 current = pool->current; |
177 | |
178 for (p = current; p->d.next; p = p->d.next) { | |
179 if ((size_t) (p->d.end - p->d.last) < NGX_ALIGNMENT) { | |
180 current = p->d.next; | |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
181 } |
2049 | 182 } |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
183 |
2049 | 184 p->d.next = new; |
185 | |
186 pool->current = current ? current : new; | |
581 | 187 |
2049 | 188 return m; |
189 } | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
190 |
2049 | 191 |
192 static void * | |
193 ngx_palloc_large(ngx_pool_t *pool, size_t size) | |
194 { | |
195 void *p; | |
196 ngx_pool_large_t *large; | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
198 #if 0 |
501 | 199 p = ngx_memalign(ngx_pagesize, size, pool->log); |
200 if (p == NULL) { | |
194
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
201 return NULL; |
2357fa41738a
nginx-0.0.1-2003-11-21-09:30:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
156
diff
changeset
|
202 } |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
203 #else |
501 | 204 p = ngx_alloc(size, pool->log); |
205 if (p == NULL) { | |
347
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
206 return NULL; |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
207 } |
f48d579daf78
nginx-0.0.3-2004-06-08-20:26:37 import
Igor Sysoev <igor@sysoev.ru>
parents:
346
diff
changeset
|
208 #endif |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 |
629 | 210 large = ngx_palloc(pool, sizeof(ngx_pool_large_t)); |
211 if (large == NULL) { | |
1317 | 212 ngx_free(p); |
629 | 213 return NULL; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
214 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
216 large->alloc = p; |
629 | 217 large->next = pool->large; |
218 pool->large = large; | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
219 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
220 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
221 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
222 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 |
501 | 224 ngx_int_t |
225 ngx_pfree(ngx_pool_t *pool, void *p) | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
226 { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
227 ngx_pool_large_t *l; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
229 for (l = pool->large; l; l = l->next) { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
230 if (p == l->alloc) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
231 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, pool->log, 0, |
461 | 232 "free: %p", l->alloc); |
477 | 233 ngx_free(l->alloc); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
234 l->alloc = NULL; |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
235 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
236 return NGX_OK; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
237 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
238 } |
436
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
239 |
9549fc9508e5
nginx-0.0.11-2004-09-23-10:32:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
429
diff
changeset
|
240 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
243 |
501 | 244 void * |
245 ngx_pcalloc(ngx_pool_t *pool, size_t size) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 { |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 void *p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
248 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 p = ngx_palloc(pool, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
250 if (p) { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 ngx_memzero(p, size); |
39
83fa61cd3d2f
nginx-0.0.1-2002-12-24-20:30:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
26
diff
changeset
|
252 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
253 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
254 return p; |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 } |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
256 |
509 | 257 |
258 ngx_pool_cleanup_t * | |
563 | 259 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size) |
509 | 260 { |
261 ngx_pool_cleanup_t *c; | |
262 | |
263 c = ngx_palloc(p, sizeof(ngx_pool_cleanup_t)); | |
264 if (c == NULL) { | |
265 return NULL; | |
266 } | |
267 | |
563 | 268 if (size) { |
269 c->data = ngx_palloc(p, size); | |
270 if (c->data == NULL) { | |
271 return NULL; | |
272 } | |
273 | |
274 } else { | |
275 c->data = NULL; | |
276 } | |
277 | |
278 c->handler = NULL; | |
509 | 279 c->next = p->cleanup; |
280 | |
281 p->cleanup = c; | |
282 | |
563 | 283 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, p->log, 0, "add cleanup: %p", c); |
284 | |
509 | 285 return c; |
286 } | |
287 | |
288 | |
289 void | |
290 ngx_pool_cleanup_file(void *data) | |
291 { | |
292 ngx_pool_cleanup_file_t *c = data; | |
293 | |
1744 | 294 ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d", |
295 c->fd); | |
563 | 296 |
509 | 297 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
298 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, | |
299 ngx_close_file_n " \"%s\" failed", c->name); | |
300 } | |
301 } | |
302 | |
303 | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
304 void |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
305 ngx_pool_delete_file(void *data) |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
306 { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
307 ngx_pool_cleanup_file_t *c = data; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
308 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
309 ngx_err_t err; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
310 |
1744 | 311 ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, c->log, 0, "file cleanup: fd:%d %s", |
312 c->fd, c->name); | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
313 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
314 if (ngx_delete_file(c->name) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
315 err = ngx_errno; |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
316 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
317 if (err != NGX_ENOENT) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
318 ngx_log_error(NGX_LOG_CRIT, c->log, err, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
319 ngx_delete_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
320 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
321 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
322 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
323 if (ngx_close_file(c->fd) == NGX_FILE_ERROR) { |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
324 ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
325 ngx_close_file_n " \"%s\" failed", c->name); |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
326 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
327 } |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
328 |
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
931
diff
changeset
|
329 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
330 #if 0 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
331 |
501 | 332 static void * |
333 ngx_get_cached_block(size_t size) | |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
334 { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
335 void *p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
336 ngx_cached_block_slot_t *slot; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
337 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
338 if (ngx_cycle->cache == NULL) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
339 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
340 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
341 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
342 slot = &ngx_cycle->cache[(size + ngx_pagesize - 1) / ngx_pagesize]; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
343 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
344 slot->tries++; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
345 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
346 if (slot->number) { |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
347 p = slot->block; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
348 slot->block = slot->block->next; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
349 slot->number--; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
350 return p; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
351 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
352 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
353 return NULL; |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
354 } |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
355 |
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
297
diff
changeset
|
356 #endif |