Mercurial > hg > nginx
comparison src/os/unix/ngx_freebsd_rfork_thread.c @ 381:02a511569afb
nginx-0.0.7-2004-07-07-19:01:00 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 07 Jul 2004 15:01:00 +0000 |
parents | 73688d5d7fc3 |
children | da8c5707af39 |
comparison
equal
deleted
inserted
replaced
380:5ce6561246a5 | 381:02a511569afb |
---|---|
28 * This threads implementation currently works on i386 (486+) and amd64 | 28 * This threads implementation currently works on i386 (486+) and amd64 |
29 * platforms only. | 29 * platforms only. |
30 */ | 30 */ |
31 | 31 |
32 | 32 |
33 char *ngx_freebsd_kern_usrstack; | 33 char *ngx_freebsd_kern_usrstack; |
34 size_t ngx_thread_stack_size; | 34 size_t ngx_thread_stack_size; |
35 | 35 |
36 | 36 |
37 static size_t rz_size; | 37 static size_t rz_size; |
38 static size_t usable_stack_size; | 38 static size_t usable_stack_size; |
39 static char *last_stack; | 39 static char *last_stack; |
40 | 40 |
41 static ngx_uint_t nthreads; | 41 static ngx_uint_t nthreads; |
42 static ngx_uint_t max_threads; | 42 static ngx_uint_t max_threads; |
43 static ngx_tid_t *tids; /* the threads tids array */ | 43 |
44 void **ngx_tls; /* the threads tls's array */ | 44 static ngx_uint_t nkeys; |
45 static ngx_tid_t *tids; /* the threads tids array */ | |
46 void **ngx_tls; /* the threads tls's array */ | |
45 | 47 |
46 /* the thread-safe libc errno */ | 48 /* the thread-safe libc errno */ |
47 | 49 |
48 static int errno0; /* the main thread's errno */ | 50 static int errno0; /* the main thread's errno */ |
49 static int *errnos; /* the threads errno's array */ | 51 static int *errnos; /* the threads errno's array */ |
234 | 236 |
235 tids[0] = ngx_pid; | 237 tids[0] = ngx_pid; |
236 | 238 |
237 /* create the threads tls's array */ | 239 /* create the threads tls's array */ |
238 | 240 |
239 if (!(ngx_tls = ngx_calloc((n + 1) * sizeof(void *), cycle->log))) { | 241 ngx_tls = ngx_calloc(NGX_THREAD_KEYS_MAX * (n + 1) * sizeof(void *), |
242 cycle->log); | |
243 if (ngx_tls == NULL) { | |
240 return NGX_ERROR; | 244 return NGX_ERROR; |
241 } | 245 } |
242 | 246 |
243 nthreads = 1; | 247 nthreads = 1; |
244 | 248 |
268 | 272 |
269 return tids[tid]; | 273 return tids[tid]; |
270 } | 274 } |
271 | 275 |
272 | 276 |
273 ngx_int_t ngx_thread_set_tls(void *value) | 277 ngx_int_t ngx_thread_key_create(ngx_tls_key_t *key) |
274 { | 278 { |
275 ngx_tls[ngx_gettid()] = value; | 279 if (nkeys >= NGX_THREAD_KEYS_MAX) { |
276 | 280 return NGX_ENOMEM; |
277 return NGX_OK; | 281 } |
282 | |
283 *key = nkeys++; | |
284 | |
285 return 0; | |
286 } | |
287 | |
288 | |
289 ngx_int_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) | |
290 { | |
291 if (key >= NGX_THREAD_KEYS_MAX) { | |
292 return NGX_EINVAL; | |
293 } | |
294 | |
295 ngx_tls[key * NGX_THREAD_KEYS_MAX + ngx_gettid()] = value; | |
296 return 0; | |
278 } | 297 } |
279 | 298 |
280 | 299 |
281 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags) | 300 ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, uint flags) |
282 { | 301 { |