diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/ngx_buf.h | 10 | ||||
| -rw-r--r-- | src/core/ngx_file.h | 6 | ||||
| -rw-r--r-- | src/core/ngx_output_chain.c | 32 |
3 files changed, 38 insertions, 10 deletions
diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h index 9ee1c588c..f652b20ef 100644 --- a/src/core/ngx_buf.h +++ b/src/core/ngx_buf.h @@ -90,15 +90,23 @@ struct ngx_output_chain_ctx_s { #endif unsigned need_in_memory:1; unsigned need_in_temp:1; -#if (NGX_HAVE_FILE_AIO) +#if (NGX_HAVE_FILE_AIO || NGX_THREADS) unsigned aio:1; +#endif +#if (NGX_HAVE_FILE_AIO) ngx_output_chain_aio_pt aio_handler; #if (NGX_HAVE_AIO_SENDFILE) ssize_t (*aio_preload)(ngx_buf_t *file); #endif #endif +#if (NGX_THREADS) + ngx_int_t (*thread_handler)(ngx_thread_task_t *task, + ngx_file_t *file); + ngx_thread_task_t *thread_task; +#endif + off_t alignment; ngx_pool_t *pool; diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h index 3ea6c28c8..301b1918b 100644 --- a/src/core/ngx_file.h +++ b/src/core/ngx_file.h @@ -23,6 +23,12 @@ struct ngx_file_s { ngx_log_t *log; +#if (NGX_THREADS) + ngx_int_t (*thread_handler)(ngx_thread_task_t *task, + ngx_file_t *file); + void *thread_ctx; +#endif + #if (NGX_HAVE_FILE_AIO) ngx_event_aio_t *aio; #endif diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index ca390e254..3bc0a307c 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -50,7 +50,7 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) ngx_chain_t *cl, *out, **last_out; if (ctx->in == NULL && ctx->busy == NULL -#if (NGX_HAVE_FILE_AIO) +#if (NGX_HAVE_FILE_AIO || NGX_THREADS) && !ctx->aio #endif ) @@ -89,7 +89,7 @@ ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) for ( ;; ) { -#if (NGX_HAVE_FILE_AIO) +#if (NGX_HAVE_FILE_AIO || NGX_THREADS) if (ctx->aio) { return NGX_AGAIN; } @@ -233,6 +233,13 @@ ngx_output_chain_as_is(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf) return 1; } +#if (NGX_THREADS) + if (buf->in_file) { + buf->file->thread_handler = ctx->thread_handler; + buf->file->thread_ctx = ctx->filter_ctx; + } +#endif + if (buf->in_file && buf->file->directio) { return 0; } @@ -559,7 +566,6 @@ ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx) #endif #if (NGX_HAVE_FILE_AIO) - if (ctx->aio_handler) { n = ngx_file_aio_read(src->file, dst->pos, (size_t) size, src->file_pos, ctx->pool); @@ -568,15 +574,23 @@ ngx_output_chain_copy_buf(ngx_output_chain_ctx_t *ctx) return NGX_AGAIN; } - } else { + } else +#endif +#if (NGX_THREADS) + if (src->file->thread_handler) { + n = ngx_thread_read(&ctx->thread_task, src->file, dst->pos, + (size_t) size, src->file_pos, ctx->pool); + if (n == NGX_AGAIN) { + ctx->aio = 1; + return NGX_AGAIN; + } + + } else +#endif + { n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); } -#else - - n = ngx_read_file(src->file, dst->pos, (size_t) size, src->file_pos); - -#endif #if (NGX_HAVE_ALIGNED_DIRECTIO) |
