Mercurial > hg > nginx
comparison src/os/unix/ngx_freebsd_rfork_thread.c @ 85:3549c2bf9eaf
nginx-0.0.1-2003-05-07-21:32:45 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 07 May 2003 17:32:45 +0000 |
parents | fab4cb00fe5b |
children | 3973260705cc |
comparison
equal
deleted
inserted
replaced
84:fab4cb00fe5b | 85:3549c2bf9eaf |
---|---|
9 extern int __isthreaded; | 9 extern int __isthreaded; |
10 | 10 |
11 | 11 |
12 typedef int ngx_tid_t; | 12 typedef int ngx_tid_t; |
13 | 13 |
14 #define NGX_MAX_THREADS 10 | |
15 | |
14 | 16 |
15 static inline int ngx_gettid(); | 17 static inline int ngx_gettid(); |
16 | 18 |
17 | 19 |
18 static char *stacks_start; | 20 static char *stacks_start; |
21 static char *last_stack; | 23 static char *last_stack; |
22 static int last_thread; | 24 static int last_thread; |
23 | 25 |
24 static ngx_log_t *log; | 26 static ngx_log_t *log; |
25 | 27 |
26 static ngx_tid_t *tids; | 28 static ngx_tid_t tids[NGX_MAX_THREADS]; |
27 | 29 |
28 static int red_zone = 4096; | 30 static int red_zone = 4096; |
29 | 31 |
30 | 32 |
31 /* the thread-safe errno */ | 33 /* the thread-safe errno */ |
32 | 34 |
33 static int errno0; /* the main thread's errno */ | 35 static int errnos[NGX_MAX_THREADS]; |
34 static int *errnos; | |
35 | 36 |
36 int *__error() | 37 int *__error() |
37 { | 38 { |
38 int tid; | 39 return &errnos[ngx_gettid()]; |
39 | |
40 tid = ngx_gettid(); | |
41 return tid ? &errnos[tid] : &errno0; | |
42 } | 40 } |
43 | 41 |
44 | 42 |
45 int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg) | 43 int ngx_create_thread(ngx_tid_t *tid, int (*func)(void *arg), void *arg) |
46 { | 44 { |
54 ngx_log_error(NGX_LOG_CRIT, log, 0, "no more threads allocated"); | 52 ngx_log_error(NGX_LOG_CRIT, log, 0, "no more threads allocated"); |
55 return NGX_ERROR; | 53 return NGX_ERROR; |
56 } | 54 } |
57 | 55 |
58 #if 0 | 56 #if 0 |
59 id = rfork_thread(RFPROC|RFMEM|RFFDG|RFCFDG, stack_top, func, arg); | 57 id = rfork(RFFDG|RFCFDG); |
60 #elif 1 | 58 #elif 0 |
59 id = rfork_thread(RFFDG|RFCFDG, stack_top, func, arg); | |
60 #elif 0 | |
61 id = rfork_thread(RFPROC|RFMEM, stack_top, func, arg); | 61 id = rfork_thread(RFPROC|RFMEM, stack_top, func, arg); |
62 #else | 62 #else |
63 id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top, func, arg); | 63 id = rfork_thread(RFPROC|RFTHREAD|RFMEM, stack_top, func, arg); |
64 #endif | 64 #endif |
65 err = errno; | 65 err = errno; |
127 | 127 |
128 stacks_start = last_stack; | 128 stacks_start = last_stack; |
129 stack_size = size + red_zone; | 129 stack_size = size + red_zone; |
130 stacks_end = stacks_start + n * stack_size; | 130 stacks_end = stacks_start + n * stack_size; |
131 | 131 |
132 /* create the thread errno array */ | |
133 ngx_test_null(errnos, ngx_calloc(n * sizeof(int), log), NGX_ERROR); | |
134 | |
135 /* create the thread tid array */ | |
136 ngx_test_null(tids, ngx_calloc(n * sizeof(ngx_tid_t), log), NGX_ERROR); | |
137 | |
138 tids[0] = ngx_getpid(); | 132 tids[0] = ngx_getpid(); |
139 last_thread = 1; | 133 last_thread = 1; |
140 | 134 |
141 return NGX_OK; | 135 return NGX_OK; |
142 } | 136 } |
152 { | 146 { |
153 char *sp; | 147 char *sp; |
154 | 148 |
155 __asm__ ("mov %%esp, %0" : "=q" (sp)); | 149 __asm__ ("mov %%esp, %0" : "=q" (sp)); |
156 | 150 |
157 return (sp > stacks_end) ? 0: ((sp - stacks_start) / stack_size + 1); | 151 return (sp > stacks_end) ? 0 : ((sp - stacks_start) / stack_size + 1); |
158 } | 152 } |