Mercurial > hg > nginx
comparison src/core/ngx_thread_pool.c @ 6042:abde398f34a7
Thread pools: implemented graceful exiting of threads.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Mon, 23 Mar 2015 17:51:21 +0300 |
parents | 2097cd49a158 |
children | 657e029bac28 |
comparison
equal
deleted
inserted
replaced
6041:2097cd49a158 | 6042:abde398f34a7 |
---|---|
44 | 44 |
45 | 45 |
46 static ngx_int_t ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log, | 46 static ngx_int_t ngx_thread_pool_init(ngx_thread_pool_t *tp, ngx_log_t *log, |
47 ngx_pool_t *pool); | 47 ngx_pool_t *pool); |
48 static void ngx_thread_pool_destroy(ngx_thread_pool_t *tp); | 48 static void ngx_thread_pool_destroy(ngx_thread_pool_t *tp); |
49 static void ngx_thread_pool_exit_handler(void *data, ngx_log_t *log); | |
49 | 50 |
50 static void *ngx_thread_pool_cycle(void *data); | 51 static void *ngx_thread_pool_cycle(void *data); |
51 static void ngx_thread_pool_handler(ngx_event_t *ev); | 52 static void ngx_thread_pool_handler(ngx_event_t *ev); |
52 | 53 |
53 static char *ngx_thread_pool(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 54 static char *ngx_thread_pool(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
161 | 162 |
162 | 163 |
163 static void | 164 static void |
164 ngx_thread_pool_destroy(ngx_thread_pool_t *tp) | 165 ngx_thread_pool_destroy(ngx_thread_pool_t *tp) |
165 { | 166 { |
166 /* TODO: exit threads */ | 167 ngx_uint_t n; |
167 | 168 ngx_thread_task_t task; |
168 #if 0 | 169 volatile ngx_uint_t lock; |
170 | |
171 ngx_memzero(&task, sizeof(ngx_thread_task_t)); | |
172 | |
173 task.handler = ngx_thread_pool_exit_handler; | |
174 task.ctx = (void *) &lock; | |
175 | |
176 for (n = 0; n < tp->threads; n++) { | |
177 lock = 1; | |
178 | |
179 if (ngx_thread_task_post(tp, &task) != NGX_OK) { | |
180 return; | |
181 } | |
182 | |
183 while (lock) { | |
184 ngx_sched_yield(); | |
185 } | |
186 | |
187 task.event.active = 0; | |
188 } | |
189 | |
169 (void) ngx_thread_cond_destroy(&tp->cond, tp->log); | 190 (void) ngx_thread_cond_destroy(&tp->cond, tp->log); |
170 | 191 |
171 (void) ngx_thread_mutex_destroy(&tp->mtx, tp->log); | 192 (void) ngx_thread_mutex_destroy(&tp->mtx, tp->log); |
172 #endif | 193 } |
194 | |
195 | |
196 static void | |
197 ngx_thread_pool_exit_handler(void *data, ngx_log_t *log) | |
198 { | |
199 ngx_uint_t *lock = data; | |
200 | |
201 *lock = 0; | |
202 | |
203 pthread_exit(0); | |
173 } | 204 } |
174 | 205 |
175 | 206 |
176 ngx_thread_task_t * | 207 ngx_thread_task_t * |
177 ngx_thread_task_alloc(ngx_pool_t *pool, size_t size) | 208 ngx_thread_task_alloc(ngx_pool_t *pool, size_t size) |