1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8

--- 69 unchanged lines hidden (view full) ---

78 if (!tp->ready) {
79
80 nxt_thread_log_debug("thread pool init");
81
82 (void) nxt_atomic_fetch_add(&tp->threads, 1);
83
84 if (nxt_fast_path(nxt_sem_init(&tp->sem, 0) == NXT_OK)) {
85
86 link = nxt_malloc(sizeof(nxt_thread_link_t));
86 link = nxt_zalloc(sizeof(nxt_thread_link_t));
87
88 if (nxt_fast_path(link != NULL)) {
89 link->start = nxt_thread_pool_start;
90 link->work.data = tp;
91
92 if (nxt_thread_create(&handle, link) == NXT_OK) {
93 tp->ready = 1;
94 goto done;

--- 137 unchanged lines hidden (view full) ---

232 nxt_thread_t *thr;
233
234 thr = nxt_thread();
235
236 nxt_log_debug(thr->log, "thread pool destroy: %d", tp->ready);
237
238 if (!tp->ready) {
239 nxt_work_queue_add(&thr->engine->fast_work_queue, tp->exit,
240 &tp->task, tp, NULL);
240 &tp->engine->task, tp, NULL);
241 return;
242 }
243
244 if (tp->max_threads != 0) {
245 /* Disable new threads creation and mark a pool as being destroyed. */
246 tp->max_threads = 0;
247
248 nxt_work_set(&tp->work, nxt_thread_pool_exit, &tp->task, tp, NULL);

--- 42 unchanged lines hidden (view full) ---

291
292 nxt_thread_pool_post(tp, &tp->work);
293
294 } else {
295 nxt_debug(task, "thread pool destroy");
296
297 nxt_sem_destroy(&tp->sem);
298
299 nxt_work_set(&tp->work, nxt_thread_pool_exit, &tp->task, tp,
299 nxt_work_set(&tp->work, tp->exit, &tp->engine->task, tp,
300 (void *) (uintptr_t) thread->handle);
301
302 nxt_event_engine_post(tp->engine, &tp->work);
303
304 /* The "tp" memory should be freed by tp->exit handler. */
305 }
306
307 nxt_thread_exit(thread);
308
309 nxt_unreachable();
310}