ngx_thread_pool_t * ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name) { ngx_thread_pool_t *tp, **tpp; ngx_thread_pool_conf_t *tcf; if (name == NULL) { name = &ngx_thread_pool_default; } tp = ngx_thread_pool_get(cf->cycle, name); if (tp) { return tp; } tp = ngx_pcalloc(cf->pool, sizeof(ngx_thread_pool_t)); if (tp == NULL) { return NULL; } tp->name = *name; tp->file = cf->conf_file->file.name.data; tp->line = cf->conf_file->line; tcf = (ngx_thread_pool_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, ngx_thread_pool_module); tpp = ngx_array_push(&tcf->pools); if (tpp == NULL) { return NULL; } *tpp = tp; return tp; }
static ngx_int_t ngx_http_copy_thread_handler(ngx_thread_task_t *task, ngx_file_t *file) { ngx_str_t name; ngx_thread_pool_t *tp; ngx_http_request_t *r; ngx_output_chain_ctx_t *ctx; ngx_http_core_loc_conf_t *clcf; r = file->thread_ctx; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); tp = clcf->thread_pool; if (tp == NULL) { if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) != NGX_OK) { return NGX_ERROR; } tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name); if (tp == NULL) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "thread pool \"%V\" not found", &name); return NGX_ERROR; } } task->event.data = r; task->event.handler = ngx_http_copy_thread_event_handler; if (ngx_thread_task_post(tp, task) != NGX_OK) { return NGX_ERROR; } r->main->blocked++; r->aio = 1; ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); ctx->aio = 1; return NGX_OK; }
static char *ngx_stream_app_init_main_conf(ngx_conf_t *cf, void *conf) { // ngx_stream_app_srv_conf_t **ascf; ngx_stream_app_main_conf_t *amcf = conf; ngx_str_t name = ngx_string("app"); // ngx_uint_t i; // ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "init_main_conf"); amcf->shm.size = amcf->shm_size; amcf->shm.log = cf->log; amcf->shm.name.len = sizeof("resource")-1; amcf->shm.name.data = (u_char *) "resource"; if (ngx_shm_alloc(&amcf->shm) != NGX_OK) { return NGX_CONF_ERROR; } /* ascf = amcf->servers.elts; for (i = 0; i < amcf->servers.nelts; i++) { ascf[i]->shm.size = amcf->shm_size; ascf[i]->shm.log = cf->log; ascf[i]->shm.name.len = sizeof("resource") - 1; ascf[i]->shm.name.data = (u_char *) "resource"; } */ amcf->tp = ngx_thread_pool_get(cf->cycle, &name); // ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "ngx_thread_pool_get"); if(amcf->tp == NULL){ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,"invalid thread_pool [app]"); return NGX_CONF_ERROR; } //TODO:load xml resource return NGX_CONF_OK; }